One of the confusing aspects of learning data contract is that WCF offering multiple approaches to define data contract. For beginners, DataContractAttribute is the most common approach to specify request and response messages, which in turn use serialization for data transfer. DataContractAttribute earns the most emphasis and is rightly so because it’s designed for WCF. So, mastering DataContractAttribute is essential.
Yet DataContractAttribute is not a one size fit all solution. Other approaches make sense for different purpose. So as you dig deeper, learn the benefit and trade off in each approach.
Here’re approaches WCF offering for data transfer. I ranked in terms of most-likely-to-use to least-likely-to-use.
- DataContractAttribute is designed for WCF serialization to handle user-defined types. Using DataContractAttribute is the preferred approach. For more information, please see The Anatomy of DataContractAttribute
- Pre-existing serialization mechanism is also applicable to WCF. These include types having SerializableAttribute and IXmlSerializable
- MessageContractAttributes offers better degree of control over SOAP message structure definition. For more information, please see The Anatomy of MessageContractAttribute
- Message class allows complete control over SOAP message specification. For more information, please see Using the Message Class
- Stream class allows large message processing. For more information, please see Large Data and Streaming