Close

WCF and Document Literal vs. RPC Encoding

Document Literal vs. RPC Encoding is the big endian-little endian of connected systems. There has been a lot said about the differences (see reference section for details) however this post is about how elegant it looks in WCF. Traditionally we had two ways to represent them;

As a web method

[WebMethod]
public int Add(int p1, int p2)
{
return p1+p2;
}
[WebMethod]
[SoapRpcMethod]
public int Add(int p1, int p2)
{
return p1+p2;
}

Or as a SoapDocumentMethod


SoapDocumentMethod(
"http://www.dotnetsmith.com/DocumentLiteral",
RequestNamespace="http://www.dotnetsmith.com",
ResponseNamespace="http://www.dotnetsmith.com",
Use=SoapBindingUse.Literal)]
public string DocumentLiteral(Address1 address, bool useZipPlus4) {

[SoapDocumentMethod(
"http://www.dotnetsmith.com/DocumentEncoded",
RequestNamespace="http://www.dotnetsmith.com",
ResponseNamespace="http://www.dotnetsmith.com",
Use=SoapBindingUse.Encoded)]
public string DocumentEncoded(Address address, bool useZipPlus4) {

With WCF's seperation of Data and Service Contracts, it has become much more cleaner and clear.

[ServiceContract]
[DataContractFormat(Style=OperationFormatStyle.Document)] //Or Rpc
public interface IOrderEntry {...}

[ServiceContract]
[XmlSerializerFormat(Style=OperationFormatStyle.Document,
Use=OperationFormatUse.Literal)] //Or Encoded
public interface IOrderEntry {...}

and the one way attribute as an operation contract.

public interface IOrderEntry
{
[OperationContract(IsOneWay = true)]
void PlaceOrder(PurchaseOrder order);
}

Remember that RPC/encoded is not WS-I compliant!

Following is difference in the output from the two different

References

Share