# SOAP Communication Styles

Generally, SOAP applications can communicate in two styles: document style and RPC style (Remote Procedure Call style).

Document Style Communication In document-style communication, the two applications agree upon the structure of documents exchanged between them. SOAP messages are used to transport these documents from one application to the other. The structure of both request and response messages is the same. There are absolutely no restrictions as to the information that can be stored in their bodies. In short, any XML document can be included in the SOAP message. The document style is often referred to also as message-oriented style.

RPC-style communication In RPC-style communication, one SOAP message encapsulates the request while another message encapsulates the response, just as in document-style communication. However, the difference is in the way these messages are constructed. As shown in Figure 4-1 below, the body of the request message contains the actual operation call. This includes the name of the operation being invoked and its input parameters. Thus, the two communicating applications have to agree upon the RPC operation signature as opposed to the document structure (in the case of document-style communication). The task of translating the operation signature in SOAP is typically hidden by the SOAP middleware.

## Selecting SOAP Communication Style

Selecting the communication style is independent from selecting whether or not the message should be encoded. The term literal is commonly used to refer to non-encoded messages. Therefore, four different combinations are possible:

• document/literal: A document-style message which is not encoded.
• document/encoded: A document-style message which is encoded.
• rpc/literal: An RPC-style message which is not encoded.
• rpc/encoded: An RPC-style message which is encoded.

The document/encoded combination is rarely encountered in practice, but the other three are commonly in use. Document-style messages are particularly useful to support cases in which RPCs result in interfaces that are too fine grained and, therefore, brittle.

## The RPC-style SOAP Communication

In the language of the SOAP encoding, the actual RPC invocation is modeled as a struct type. The name of the struct (that is, the name of the first element inside the SOAP body) is identical to the name of the method/operation. Every in or in-out parameter of the RPC is modeled as an accessor with a name identical to the name of the RPC parameter and the type identical to the type of the RPC parameter mapped to XML according to the rules of the active encoding style. The accessors appear in the same order as do the parameters in the operation signature.

All parameters are passed by value. SOAP has no notion of passing values by reference, which is unlike most of the programming languages. For Web services, the notion of in-out and out parameters does not involve passing objects by reference and letting the target application modify their state. Instead, copies of the data are exchanged. It is the up to the service client code to create the perception that the actual state of the object that has been passed in to the client method has been modified.

<?xml version="1.0"?>
<description name="StockQuote"
targetNamespace="http://example.com/stockquote.wsdl"
xmlns:tns="http://example.com/stockquote.wsdl"
xmlns:xsd1="http://example.com/stockquote.xsd"
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns="http://www.w3.org/ns/wsdl">
<types>
<schema targetNamespace="http://example.com/stockquote.xsd"
xmlns="http://www.w3.org/2001/XMLSchema">
<complexType>
<all>
<element name="tickerSymbol" type="string"/>
</all>
</complexType>
</element>
<complexType>
<all>
<element name="price" type="float"/>
</all>
</complexType>
</element>
</schema>
</types>
</message>
</message>
<portType name="StockQuotePortType">
</operation>
</portType>
<binding name="StockQuoteSoapBinding"
type="tns:StockQuotePortType">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<soap:operation
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="StockQuoteService">
<documentation>My first service</documentation>
<port name="StockQuotePort" binding="tns:StockQuoteBinding">