Soap Fight: RPC vs. Document

By Charles Skinner

Bixby Consulting Inc.

http://www.eherenow.com

 

The line has been drawn and both camps are playing for keeps.  This is sure to be a good fight with one winner becoming the VHS of our time and other suffering the fate of BETAMAX.  Who it will be?  Let’s have a little ring side analysis.

 

Most people are lead to believe that there are only two implementations, Document or RPC.  As in everything, there are more choices that need to be made.  In reality, the choices are between what combo of Style and Use to implement: RPC/ENCODING. RPC/LITERAL and DOCUMENT/LITERAL.  When people refer to RPC this usually indicates style: RPC and use: ENCODE. On the other hand Document usually refers to style: Document and use: Literal.

The fighters have STYLE:

 

 

What they are USEing:

o         Each part references a concrete schema definition using either the element or type attribute; in other words, data is serialized according to a given schema.

 

Contender 1: RPC/Encoded

 

In RPC style Web Services, the complete method is specified in the WSDL file and in the SOAP body.  This includes the sent parameters and the return values. So, you have a rather tight coupling with this style.  The Encoded- USE indicates that the SOAP message will contain the encoded type information such as xsi:type="xsd:int", xsi:type="xsd:string", xsi:type="xsd:double".

Strengths:

·        The definition of the WSDL file formatted in a 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.

·        Most early Java implementations only use this method.

Weaknesses:

 

Sample Soap Message

========================Request Sample ===========================
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://eherenow.com/RPC" xmlns:types="http://eherenow.com/RPC/encodedTypes" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <q1:GetUserName xmlns:q1="http://www.eherenow.com">
      <Where xsi:type="xsd:string">string</Where>
    </q1:GetUserName>
  </soap:Body>
</soap:Envelope>
 
========================Response Sample ===========================
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://eherenow.com/RPC" xmlns:types="http://eherenow.com/RPC/encodedTypes" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <q2:GetUserNameResponse xmlns:q2="http://www.eherenow.com">
      <GetUserNameResult href="#id1" />
    </q2:GetUserNameResponse>
    <types:UserName id="id1" xsi:type="types:UserName">
      <Name xsi:type="xsd:string">string</Name>
      <Domain xsi:type="xsd:string">string</Domain>
    </types:UserName>
  </soap:Body>
</soap:Envelope>

 

Contender 2: RPC/Literal Style

The style will remain RPC but the WSDL will now have the 'use' setting changed from 'encoded' to 'literal' in the soap:body.  Which means the data is serialized according to the given schema.

 

Strengths:

 

 

Weaknesses:

·        Any changes to the interface would break the contract between the service and the client because there is a tight coupling between the service provider and the client.

Contender 3: Document/Literal

In Document style Web Services, the client sends standard XML document to the server.  The server application is responsible for mapping the server objects (parameters, method calls, and so forth) and the values in XML documents. The protocol places no constraint on how the document needs to be structured.

 

As described before the 'use' setting is set to 'literal' in the soap:body.  Which means the data is serialized according to the given schema.

 

Strengths:

 

 

Weaknesses:

 

 

Sample Soap Message

========================Request Sample ===========================
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Where xmlns="http://www.eherenow.com">string</Where>
  </soap:Body>
</soap:Envelope>
 
========================Response Sample ==========================
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetUserNameResult xmlns="http://www.eherenow.com">
      <Name>string</Name>
      <Domain>string</Domain>
    </GetUserNameResult>
  </soap:Body>
</soap:Envelope>

 

Contender 4: Document/Literal MICROSOFT PROPOSAL

How many Microsoft programmers does it take to change a light bulb . . . NONE – they will make darkness a standard. 

 

I thought I should mention this new contender because when an elephant walks the ground moves.  Microsoft suggested this style to fix the “drawbacks” from the standard Document/Literal style.  It is exactly the same as Contender 3 except for one difference; the message is wrapped by an element that describes the method name.

 

Even though there is no specification in the WSDL 1.1 standard for this style, many current SOAP toolkits support it.

 

Strengths:

 

 

Weaknesses:

 

 

Sample Soap Message

=========================Request Sample =======================
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetUserName xmlns="http://www.eherenow.com">
      <Where>string</Where>
    </GetUserName>
  </soap:Body>
</soap:Envelope>
======================= Response Sample ========================
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetUserNameResponse xmlns="http://www.eherenow.com">
      <GetUserNameResult>
        <Name>string</Name>
        <Domain>string</Domain>
      </GetUserNameResult>
    </GetUserNameResponse>
  </soap:Body>
</soap:Envelope>

 

Conclusion

Well sport fans, we have sized up the contenders for you and it appears that in a toe to toe match document style usually wins.  In fact, the WS-I Basic profile 1.1 discourages the use of RPC/Encoded approach and motivates Document/Literal and RPC/Literal as the only allowed style/use combination. Rumor has it that RPC/Literal would go away with a future version of the WSI profile.  So it appears, unless you are interfacing to a legacy RPC style, Document/Literal will be a sure bet every time. 

 

Sample Links

 
http://www.eherenow.net/engine/transformhere.asmx
http://66.223.18.114/ConnectHub/Connect.asmx