Summary
Web Services technology is well established as a communication technology for the Internet offering greatest interoperability. Their standardization process is going on great speed, which will lead to even broader acceptance. Nonetheless judging from mailing lists and user groups, discussions there is still quite some confusion about the different Web Services Design approaches. What does "Document/Literal" mean compared "RPC-style", how does SOAP "message-style" fit into this?
This article will clarify and explain in detail the different Web Service Design Methodologies as defined by the Web Services Standardization Groups, clarify the terms, highlight their differences. Here we will be focused on the following Web Services Design Approaches evaluate their Strength and weaknesses and explore how far each style supports in designing an Interoperable Web Service.
- RPC/Encoded Style
- RPC/Literal Style
- Document/Literal Style
- Document /Literal Wrapped Style
Introduction
In their relatively short time of existence Web Services have gained an enormous acceptance and a broad usage on the market. One reason for this surely is their very early open standardization which has bee driven by all major players on the market. On the other side, all these players also have their preferences on how Web Services should look like and how they should communicate. This, and the fact, that different communication styles are required, has lead to standards that today support different ways how web services messages can be formatted and how they can communicate.
The relevant standards for describing and using Web Services are the Web Services Description Language (WSDL), a standardized XML Schema-like language is used for specifying Web Service and the Simple Object Access Protocol (SOAP), the actual communication protocol for Web Services ([WSDL], [SOAP].
Before Moving to the Real Design Approaches lets Clarify some of the Terms that is frequently used in the world of web services.
Communication Patterns
Let's start with the communication patterns. With Web Services we can essentially distinguish three different ways of communication:
- Remote procedure call: Client sends a SOAP request to the service provider waits for a SOAP response (synchronous communication).
- Messaging: Client sends a SOAP request and expects no SOAP response back (one-way communication)
- Asynchronous callback: A client calls service with one of the above methods. Later, the two parties switch roles for a callback call. This pattern can be build from either of the first two.
SOAP Formatting Rules
Now let's turn to how the SOAP Message of a Web Services can be formatted (essentially the message's <soap:body> Element) WSDL 1.1 distinguishes two different binding styles (referred to as soap:binding styles): RPC and Document.
- RPC Style
The RPC style specifies that the <soap:body> contains an element with the name of the web method being invoked (wrapper element). This element in turn contains an entry for each parameter and the return value of this method - Document Style
If the style is of type document, there is no wrapper element as with the RPC style. Instead, the message parts appear directly under the <soap:body> element. There are no SOAP formatting rules for what the <soap:body> contains; it contains what the sender and receiver agreed upon as an XML document.
The second formatting rule is the 'Use' attribute. This concerns how types are represented in XML. It indicates whether the message parts are encoded using some encoding rules, or whether the parts define the concrete schema of the message. The two offered choices are:
- Encoding
If use is encoded, then each message part references an abstract type using the type attribute. The message is produced using an encoding specified by the encodingStyle attribute. The mostly used SOAP Encoding is a set of serialization rules defined in SOAP 1.1. The rules specify how objects, structures, arrays and object graphs should be serialized. In general the applications using SOAP encoding is focused on remote procedure calls and will likely use RPC message style. - Literal
If use is Literal, then each part references a concrete schema definition using either the element or type attribute, i.e. data is serialized according to a given schema. In practice, this schema is usually expressed using W3C XML Schema.
Table 1 summarizes the options for different web services parameters. An important realization is that three independent decisions are to be made by a web services developer. What is the "Communication Pattern" to be used? What is the SOAP formatting "Style" to be used ? and finally what is the SOAP message encoding Type to be used ?
| WSDL Parameters | Available Options |
| Communication Patterns | Remote Procedure Call or One-way messaging |
| Style | Document or RPC |
| Use | Encoded or Literal |
Table 1. Web Services Parameters
Although in theory any combination of these options is possible, in practice there is a clear preference of one combination over the other, and also the standards and the Web Services Interoperability organization (WS-I) has a clear preference.
Thus in practice only Document/Literal and RPC/Encoded have gained wide spread usage and are directly supported by most platforms as indicated in Table 2. The table shows also the results of the WS-I conformance tests for the different style/use combinations.
| Style/Use combination | Supported Soap tool kit | WS-I Conformance |
| RPC/Encoded | Microsoft, Axis 1.1 | Failed |
| RPC/Literal | Axis 1.1 | Failed |
| Document/Literal | Microsoft , Axis 1.1 | Passed |
Table 2. Web Services Format Support
The Document/Encoded has not been tested, since it is not supported by the used platforms. In fact there is no real world usage of Document/Encoded combination.
A Simple Web Service Example
Now let's look in more detail into the mostly used and supported style/use formats RPC/Encoded and Document/Literal. We will illustrate each of this style use combinations by means of a web method called "SendTemperature" which takes a user defined complex object as its parameter and returns void type as described in listing 1.
We choose an example with a complex data type to make the differences between the various styles more obvious.
public void SendTemperature (Temperature[] TempCollection){}
public class Temperature
{
/// <remarks/>
public int Id;
/// <remarks/>
public string Name;
/// <remarks/>
public System.Double Temperature;
}
Listing 1. SendTemperature Web Method implemented in C#
We will show how the various Web Services formats are implemented in the WSDL file for this web method with their respective SOAP request formats and highlight their differences. The implementations were done using Microsoft VS.NET and the Axis soap toolkit.
Note that the namespaces, prefixes and the service part of the WSDL files that follows in this article have been ignored for simplicity. The Listing 2 shows the common namespaces and prefixes that were used.
xmlns:http=http://schemas.xmlsoap.org/wsdl/http/
xmlns:soap=http://schemas.xmlsoap.org/wsdl/soap/
xmlns:s=http://www.w3.org/2001/XMLSchema
xmlns:s0=http://interop.webservices.fhso.ch/{service name}
xmlns:soapenc=http://schemas.xmlsoap.org/soap/encoding/
xmlns:tm=http://microsoft.com/wsdl/mime/textMatching/
xmlns:mime=http://schemas.xmlsoap.org/wsdl/mime/
xmlns=http://schemas.xmlsoap.org/wsdl/
targetNamespace=http://interop.webservices.fhso.ch/{service name}/
Listing 2. Namespaces and used prefixes
1. RPC/Encoded Style
RPC/Encoded is essentially a format following the classical "remote procedure call" style in which a client sends a synchronous request to a server to execute an operation. The SOAP request contains the name of method to be executed and the parameter it takes. The server running the Web Service converts this request to appropriate objects, executes the operation and sends the response back to the client as SOAP message. At the client side, this response is used to form appropriate objects and return the required information to the client. In RPC-style Web Services the complete method is specified in the WSDL file and in the SOAP body, including the sent parameters and the return values. So we have a rather tight coupling with this style.
Listing 3 shows the WSDL defined for the SendTemperature Method in the RPC/Encoded style.
<types>
<s:schema targetNamespace="http://interop.webservices.fhso.ch/rpcencoded">
<s:complexType name="ArrayOfTemperature">
<s:complexContent mixed="false">
<s:restriction base="soapenc:Array">
<s:attribute d7p1:arrayType="s0:Temperature[]" ref="soapenc:arrayType"
xmlns:d7p1="http://schemas.xmlsoap.org/wsdl/"/>
</s:restriction>
</s:complexContent>
</s:complexType>
<s:complexType name="Temperature">
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="Id" type="s:int"/>
<s:element minOccurs="1" maxOccurs="1" name="Name" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="value" type="s:double"/>
</s:sequence>
</s:complexType>
</s:schema>
</types>
<message name="SendTemperatureSoapIn">
<part name="Collection" type="s0:ArrayOfTemperature"/>
</message>
<message name="SendTemperatureSoapOut"/>
<portType name="TemperatureRpcEncodedSoap">
<operation name="SendTemperature">
<input message="s0:SendTemperatureSoapIn"/>
<output message="s0:SendTemperatureSoapOut"/>
</operation>
</portType>
<binding name="TemperatureRpcEncodedSoap" type="s0:TemperatureRpcEncodedSoap">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="SendTemperature">
<soap:operation soapAction="http://interop.fhso.ch/soapformat/SendTemperature"/>
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
Listing 3. RPC/Encoded WSDL for SendTemperature
Notice the binding style, which is set to 'rpc' and use, which is set to 'encoded'. Under the <message> section there can be any number of <part> elements each containing a type attribute which is unique to 'rpc' style. Now let's look what happens when we invoke the SendTemperature web method, sending an array with two entries. Listing 4 shows the resulting SOAP message.
<soap:Envelopexmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://interop.webservices.fhso.ch/rpcencoded" xmlns:types="http://interop.webservices.fhso.ch/rpcencoded/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SendTemperature>
<Collection href="#id1"/>
</SendTemperature>
<soapenc:Array id="id1" soapenc:arrayType="tns:Temperature[2]">
<Item href="#id2"/>
<Item href="#id3"/>
</soapenc:Array>
<tns:Temperature id="id2" xsi:type="tns:Temperature">
<Id xsi:type="xsd:int">3</Id>
<Name xsi:type="xsd:string">Station1</Name>
<value xsi:type="xsd:double">34.3</value>
</tns:Temperature>
<tns:Temperature id="id3" xsi:type="tns:Temperature">
<Id xsi:type="xsd:int">56</Id>
<Name xsi:type="xsd:string">Station3</Name>
<value xsi:type="xsd:double">23.6</value>
</tns:Temperature>
</soap:Body>
</soap:Envelope>
Listing 4. RPC/Encoded SOAP Message for SendTemperature
Each parameter is type encoded in the SOAP message. Notice also the 'href' tags in the SOAP message, which is an essential part of the RPC/Encoded style and which is used to reference the items in the array. Under any literal style, the 'href' tag is not available. Let's analyze the WSDL and its SOAP message format.
Strengths
- The definition of the WSDL file follows the intuitive and well-known remote-procedure-call style.
- The operation name appears in the message, so that the receiver has an easy time dispatching the message to its implementation.
- If you are using data graphs or polymorphism in your service this is the only possible style that can be used for the types described in this article.
Weaknesses
- The SOAP message includes the type encoding information such as
xsi:type="xsd:int" , xsi:type="xsd:string" , xsi:type="xsd:double" which is an overhead. - In general it is harder to validate the SOAP message.
- RPC style causes a rather tight coupling between service provider and client, any changes to the interface would break the contract between the service and the client.
- Depending on the information that may need to be handled simultaneously, memory constraints may make RPC messaging unfeasible as marshalling takes place in-memory.
- Is not supported by the WSI conformance standard
Now let's look at the implementation of the same Web Method in RPC/Literal format and see if it can eliminate some of the drawbacks of RPC/Encoded style.
2. RPC/Literal Style
The WSDL looks almost similar to the previous one except the change in the 'use' setting from 'encoded' to 'literal' in the soap:body as shown in Listing 5. As described above, this means that the data type definition is not provided by the referenced XML Schema instead of RPC encoding.
<types>
<s:schema elementFormDefault="qualified"
targetNamespace="http://interop.webservices.fhso.ch/rpcliteral">
<!-- there are no global elementdeclarations. There's nothing in the
schema that completely describes the content of soap:Body -->
<s:complexType name="ArrayOfTemperature">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="Temperature" nillable="true"
type="s0:Temperature"/>
</s:sequence>
</s:complexType>
<s:complexType name="Temperature">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Id" type="s:int"/>
<s:element minOccurs="0" maxOccurs="1" name="Name" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="value" type="s:double"/>
</s:sequence>
</s:complexType>
</s:schema>
</types>
<message name="SendTemperatureSoapIn">
<part name="Collection" type="s0:ArrayOfTemperature"/>
</message>
<message name="SendTemperatureSoapOut"/>
<portType name="TemperatureRpcLiteralSoap">
<operation name="SendTemperature">
<input message="s0:SendTemperatureSoapIn"/>
<output message="s0:SendTemperatureSoapOut"/>
</operation>
</portType>
<binding name="TemperatureRpcLiteralSoap" type="s0:TemperatureRpcLiteralSoap">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="SendTemperature">
<soap:operation soapAction="http://interop.fhso.ch/soapformat/SendTemperature"/>
<input>
<soap:body use="literal" namespace="http://interop.fhso.ch/soapformat/SendTemperature"/>
</input>
<output>
<soap:body use="literal" />
</output>
</operation>
</binding>
Listing 5. RPC/Literal WSDL for SendTemperature
However there is still a major drawback with this style. The XML Schema alone does not tell you what the message body Infoset contains, you must also know the RPC rules. Therefore, the schema describing an RPC/Literal message is not sufficient to validate that message.
Now let's look at the SOAP message format for RPC/Literal shown in Listing 6. Note that the type encoding is completely removed.
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<!-- SendTemperature is the nameof the procedure being invoked. Collection is a parameter of that procedure.
Note that Collection is not namespace qualified. The two Temperature elements are contents of the Collection
parameter. This Collection can be thought of as an array of Temperature items. Note that the Temperature is
namespace qualified but is in a different namespace than SendTemperature. These namespace rules are unique
to RPC-style messages -->
<SendTemperature xmlns="http://interop.fhso.ch/soapformat/SendTemperature">
<Collection xmlns="">
<ns1:Temperature xmlns:ns1="http://interop.webservices.fhso.ch/rpcliteral">
<ns1:Id>2</ns1:Id>
<ns1:Name> Station1</ns1:Name>
<ns1:value>34.2</ns1:value>
</ns1:Temperature>
<ns2:Temperature xmlns:ns2="http://interop.webservices.fhso.ch/rpcliteral">
<ns2:Id>56</ns2:Id>
<ns2:Name> Station 3</ns2:Name>
<ns2:value>23.6</ns2:value>
</ns2:Temperature>
</Collection>
</SendTemperature>
</soapenv:Body>
</soapenv:Envelope>
Listing 6. RPC/Literal SOAP message for SendTemperature
Strengths
Gowtham RajamanickamPosted Apr 25, 2015, 6:34 AM
great
Gowtham RajamanickamPosted Apr 25, 2015, 6:34 AM
good