Windows Communication Foundation (WCF) data contract system is that contracts can evolve over time in nonbreaking ways. That is, a client with an older version of a data contract can communicate with a service with a newer version of the same data contract, or a client with a newer version of a data contract can communicate with an older version of the same data contract.
You can apply most of the versioning features on an as-needed basis when new versions of an existing data contract are created. However, one versioning feature,
round-tripping, must be built into the type from the first version in order to work properly.
Round-Tripping
Round-tripping occurs when data passes from a new version to an old version and back to the new version of a data contract. Round-tripping guarantees that no data is lost. Enabling round-tripping makes the type forward-compatible with any future changes supported by the data contract versioning model.
To enable round-tripping for a particular type, the type must implement the
IExtensibleDataObject interface. The interface contains one property,
ExtensionData (returning the
ExtensionDataObject type). The property stores any data from future versions of the data contract that is unknown to the current version.
Example
The following data contract is not forward-compatible with future changes.
[DataContract] public class Contact { [DataMember] public string Name; } |
To make the type compatible with future changes (such as adding a new data member named "DisplayNumber"), implement the IExtensibleDataObject interface.
[DataContract] public class Person : IExtensibleDataObject { [DataMember] public string Name;
private ExtensionDataObject theData; public virtual ExtensionDataObject ExtensionData { get { return theData; } set { theData = value; } } } |
For more information, see Best Practices: Data Contract Versioning.
Posted
Dec 31 2008, 01:19 AM
by
Damir Dobric