WCF

WCF Examples

WCF

WCF Projects

WCF Project

adplus-dvertising
Data Contract Equivalence
Previous Home Next

Two data contracts are considered equivalent if they have the same wire representation means if they have the same schema. This can be the case if they define the same type (but not necessarily the same version of the type) or if the two data contracts refer to two different types with the same data contract and data member names. Equivalent data contracts are interchangeable: WCF will let any service that was defined with one data contract operate with an equivalent data contract.

these two data contracts are equivalent

[DataContract]
struct Contact
{
   [DataMember]
   public string FirstName;
	[DataMember]
   public string LastName;
}
[DataContract(Name = "Contact")]
struct Person
{
   [DataMember(Name = "FirstName")]
   public string Name;
	[DataMember(Name = "LastName")]
   public string Surname;
}
Serialization Order

Equivalent data contracts must serialize and deserialize their members in the same order.

when serializing a Customer instance, defined as:

[DataContract]
class Contact
{
   [DataMember]
   public string FName;

   [DataMember]
   public string LName;
}
[DataContract]
class Customer : Contact
{
   [DataMember]
   public int CNumber;

The members will be serialized in the following order: FName,LName, CNumber.

The problem is that combining data contract hierarchy with aliasing contracts and members might break the serialization order

To resolve this conflict,we provide WCF with the order of serialization by setting the Order property of the DataMember attribute. The Order property defaults to -1, meaning the default WCF ordering, but you can assign to it values indicating the required order.

[DataContract(Name = "Customer")]
public class Person
{
[DataMember(Name = "FirstName",Order = 1)]
public string Name;
[DataMember(Name = "LastName",Order = 2)]
public string Surname;
[DataMember,Order = 3)]
public int CustomerNumber;blic int CNumber;
Previous Home Next