Data Contracts
A data contract describes how CLR types map to XSD schema
definitions. Data contracts are the preferred way to enable serialization of complex types
included in operation signatures as parameters or return values. You create a data contract
by applying theDataContractAttribute to a type. To
include members in serialization, you decorate them with the DataMemberAttribute; this is an opt-in process that has nothing to do with
visibility of members (public, protected, private). By default, serialization is handled by
the DataContractSerializer, a new serializer for WCF that
succeeds the XmlSerializer used for earlier technologies
such as ASMX.
In this section, you will become acquainted with the key features of data contracts and common serialization practices, including the following:
How to apply data contract attributes to exercise control over type serialization
Version tolerance and data contract versioning techniques
Implementing
IExtensibleDataObjectto support version toleranceHow to work with polymorphic types in the service contract
How enumerations, arrays, and collections are serialized
First you’ll complete a lab that illustrates many of these scenarios, and then I’ll explain the related attributes and features in greater detail.
Lab: Working with Data Contracts
For this lab you will modify a preexisting type, turning it into a data contract so
that it can be included in the service contract. Using the DataContractAttribute and the DataMemberAttribute, you will ...
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