This documentation is archived and is not being maintained.

How to: Control the Overall SOAP Body Formatting for a Web Service Method 

For overall SOAP body formatting, or style, the Web Services Description Language (WSDL) provides two choices: RPC and document. The .NET Framework controls these choices in code using attributes.

To specify a Document formatting style

  • Apply a SoapDocumentMethod attribute to the method in the proxy class calling the applicable Web service method.

    With the Document formatting style Web services created using ASP.NET support, use of both the Literal and Encoded parameter formatting styles. The following example combines the Document method formatting style with the Literal parameter formatting style.

    public string DocumentWrappedLiteral(Address MyAddress, 
                                         bool useZipPlus4) {

    <SoapDocumentMethod("", _
                        RequestNamespace:="", _
                        ResponseNamespace:="", _
                        Use:=SoapBindingUse.Literal)> _
       Public Function DocumentWrappedLiteral(ByVal MyAddress As Address, _
                                 ByVal useZipPlus4 As Boolean)As String

    With the Document formatting style, an XSD schema is defined within the service description that defines both the SOAP request and SOAP response. The following is an excerpt from the service description for the SOAP request for the DocumentWrappedLiteral Web service method. Since the first parameter to the DocumentWrappedLiteral Web service method is a class, and the Literal parameter formatting style was specified, an XSD schema is created for the address type.

    <s:element name="DocumentWrappedLiteral">
           <s:element minOccurs="1" maxOccurs="1" name="MyAddress"
                      nillable="true" type="s0:Address" /> 
           <s:element minOccurs="1" maxOccurs="1" name="useZipPlus4"
                      type="s:boolean" /> 
    <s:complexType name="Address">
          <s:element minOccurs="1" maxOccurs="1" name="Street"
                     nillable="true" type="s:string" /> 
          <s:element minOccurs="1" maxOccurs="1" name="City"
                     nillable="true" type="s:string" /> 
          <s:element minOccurs="1" maxOccurs="1" name="Zip" nillable="true"
                     type="s:string" /> 

    Given the XSD schema defined in the service description, the XML portion of the SOAP request to the DocumentWrappedLiteral Service method follows. Note that the XML elements beneath the Body element in the SOAP request match the elements defined in the XSD schema.

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi=""
        <DocumentWrappedLiteral xmlns="">

To specify RPC formatting style

  • Apply a SoapRpcMethod attribute to the method in the proxy class calling the applicable Web service method.

    public Address Rpc(Address address, bool useZipPlus4) {

    <SoapRpcMethodAttribute("", _
                            RequestNamespace:="", _
                            ResponseNamespace:="")> _
    Public Function Rpc(ByVal address As Address, _
                        ByVal useZipPlus4 As Boolean) As Address

    An XSD schema is not strictly defined in the service description for either the SOAP request or SOAP response to the Rpc method in the previous example, but rather just the parts that comprise them. Therefore, look at the SOAP request for the Rpc method, noting that the parameters are encapsulated inside one element and they are encoded using the Encoded parameter formatting.

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi=""
      <soap:Body soap:encodingStyle="">
          <address href="#1" />
        <tnsTypes:Address id="1">
          <Street id="2">string</Street>
          <City id="3">string</City>
          <Zip id="4">string</Zip>

See Also