WCF Contracts and Serialization
So far I’ve talked about the standards behind it all, but in fact WCF hides most of this from the developer by providing a programming interface for designing service contracts and controlling the message format. Application messaging requirements are described by contracts in WCF. There are three types of formal contracts that clients and services rely on to control messaging. The service contract describes the operations exposed by a particular service endpoint. Each operation, through parameters and return types, defines the format of request and response messages. A data contract describes how a complex type is serialized as part of a message. Data contracts are the preferred way to include complex types in a service contract. A message contract provides control over the format of the entire SOAP message, including support for custom message headers and individual body elements that can be described by data contracts.
By default, message serialization is handled by the DataContractSerializer. This is a new serializer introduced with WCF that
requires all types to opt-in their exact requirements for serialization—in compliance with
SOA tenets. The DataContractSerializer can serialize data
contracts, message contracts, and other serializable types such as those marked with the
SerializableAttribute or those that inherit IXmlSerializable (see Figure 2-2). It is also
possible to tell WCF to use the XmlSerializer that ASP.NET web services use (useful ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access