Sunday, July 13, 2008

Message Contracts Vs Data Contracts in WCF

There's a big confusion among WCF developers while understanding the concept of Message Contracts. Are they really required? Why were they included in WCF when Data Contracts can do everything.

Well the truth is that both Message Contracts and Data Contracts possess their own niche in SOAP messaging. In the below table, I'll be drawing a thick line to show differences between Message Contracts and Data Contracts

Data Contracts Message Contracts
Data Contracts primarily target the XSD schema definitions of Soap Messages Message Contracts primarily target the <soap:Header> and <soap:Body> construction
Data Contracts can control only the contents of Soap message data. Just the types between the <soap:Body> section Message Contracts can control the whole SOAP message
Data Contracts are mostly used while dealing with serialized types within the message body Message Contracts are mostly used while passing security information as tokens, correlation guids into the soap headers
Data contracts take care of the Data Structures of the message e.g. defining complex types, collections, etc Message Contracts take care of the overall message structure of the WSDL

 


No comments: