WCF Services—Understanding Data Contracts
|Visual C# Tutorials|
|.NET Framework Tutorials|
|© 2007 Chris Peiris, Dennis Mulder|
Understanding Data Contracts
Data contracts, in WCF, are the preferred method of abstracting your .NET types from the schema and XML serialized types. With WCF, you have choices for creating the metadata that is used to publish your service and how that impacts the runtime serialization of your .NET types into platform-agnostic schema types that are represented in XML.
The process is all hidden, if you choose, from the developer. Primitive types are easily mapped to leverage the default
DataContractSerializer. Other types are controllable through the
DataContract attribute capabilities. However, if you still want control, you can always leverage
XmlSerializer to manage the serialization of your types into XML. So, in the following sections, we’ll first walk you through some of the ways you can work with
XmlSerializer before moving on to data contracts.
All the examples so far have leveraged the default
DataContractSerializer type for XML serialization/deserialization. You’ll take a brief look at levering
XmlSerializer for managing the XML serialization process.