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
IExtensibleDataObject
to 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 ...
Get Learning WCF now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.