How to consume an rpc-literal WS using .NET?

This post is part of Issue 8’s answer

The previous post in this answer series discussed rpc-literal from a platform independent standpoint, where this post focuses on the consumption of such services using .NET. You may ask why consumption only? Well, rpc-literal is so bad that you won’t use it for your own services. Would you?

Coming back to the original question: One of our business partners provides us with an rpc-literal wsdl contract. How do we consume such a service using .NET?

If you’re not that familiar with .NET Web Services you may just answer: „By simply adding a Web Reference to my VS project”. Unfortunately, by doing so you’ll get an incomplete proxy containing a comment section similar to the one bellow:

   // CODEGEN: The operation binding 'xxx from namespace ‘xxx' was ignored.

   // The combination of style=rpc with use=literal is not supported.

The reason for this error is straight forward:.NET Fx 1.0 and 1.1 don’t support rpc-literal Web Services out of the box. However, the upcoming version of the .NET Fx (2.0) will support rpc-literal. In Fx 2.0, you can easily specify a service or a method as rpc-literal by simply applying the SoapRpcService or SoapRpcMethod attribute:

   [SoapRpcService(Use = SoapBindingUse.Literal)]

   [WebMethod]

  public int Add(int a, int b)

If you’re using current .NET technology, the simplest approach to work with rpc-literal is to convert the rpc-literal wsdl into an equivalent doc-literal one. This is possible, because rpc-literal is a subset of doc-literal. Therefore, every rpc-literal message can be built using doc-literal bindings.

Here’s an example:

The following rpc-literal message

   <soap:body>
<x:Add xmlns:x=“operationNS”>
<a>200</a>
<b>400</b>
</x:Add>

</soap:body>

can easily be constructed using the following schema element within a doc-literal binding :

  

   <xsd:schema targetNamespace="operationNS"

      xmlns:tns="operationNS">

   <xsd:element name="Add" type="tns:AddType" />

  <xsd:complexType name="AddType">

      <xsd:sequence>

      <xsd:element name="a" type="xsd:int" />

      <xsd:element name="b" type="xsd:int" />

   </xsd:sequence>

   </xsd:complexType>

   </xsd:schema>

Yasser wrote a great article about the two encodings and described the conversion process from rpc-literal to document-literal.

Once you’ve converted the wsdl to doc-literal, it’s straight forward to generate a proxy or a stub using the ordinary wsdl.exe.

The last post in this answer series is going to discuss why you shouldn’t use rpc-literal. Stay tuned…