There are two options when it comes to encoding in the context of webservices, e.g. .NET and Weblogic use document literal encoding while IBM and other vendors (Java) use RPC encoding. What is the difference and which one is better for which scenarios? Also, how easy is it to switch between the two?

Well for those new to webservices, there are two options that you can choose when encoding your wsdl messages.

So, how do they look like. If I “borrow” and example from Sun , if below was your original class in Java:

package com.examples.xmlstring; import java.rmi.Remote; import java.rmi.RemoteException; public interface IStringService extends Remote {     public String sayXMLHello(String xml)         throws RemoteException;     }

The rpc encoding for that looks like this:

<binding name="IStringServiceBinding" type="tns:IStringService">     <soap:binding transport="" **style="rpc"**/>     <operation name="sayXMLHello">         <soap:operation soapaction=""/>             <input>                 <soap:body encodingstyle="" **use="encoded"** namespace=""/>             </input>             <output>                 <soap:body encodingstyle="" **use="encoded"** namespace=""/>             </output>     </operation> </binding>

And the document encoding looks like:

<?xml version="1.0" encoding="UTF-8"?>     <env:envelope xmlns:env="" xmlns:xsd="" xmlns:xsi="" xmlns:enc="" xmlns:ns0="">         <env:body>             <ns0:sayxmlhello>                 <string_1>Hello World</string_1>             </ns0:sayxmlhello>         </env:body> </env:envelope>

I think in the end the real thing to keep in perspective is who and what will be consuming this? If your clients are primarily MS-based (COM/.NET) then you are better off with literal encoding, on the other hand if its primarily J2EE client then you are better off with the other one. But, more interestingly if you don’t know (or in other words can be both), then which road to take?