Skip to Main Content
Programming WCF Services
book

Programming WCF Services

by Juval Lowy
February 2007
Intermediate to advanced content levelIntermediate to advanced
634 pages
16h 1m
English
O'Reilly Media, Inc.
Content preview from Programming WCF Services

Data Contract Equivalence

Two data contracts are considered equivalent if they have the same wire representation. This can be the case when defining 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 names for the contract and the members. Equivalent data contracts are interchangeable: WCF will let any service that was defined with one data contract operate on an equivalent data contract.

The most common way of defining an equivalent data contract is to use the Name property of the DataContract or DataMember attribute to map one data contract to another. In the case of the DataContract attribute, the Name property defaults to the type’s name, so these two definitions are identical:

[DataContract]
struct Contact
{...}

[DataContract(Name = "Contact")]
struct Contact
{...}

In fact, the full name of the data contract always includes its namespace as well, but as you have seen, you can assign a different namespace. In the case of the DataMember attribute, the Name defaults to member name, so these two definitions are identical:

[DataMember]
public string FirstName;

[DataMember(Name = "FirstName")]
public string FirstName;

By assigning different names to the contract and the members you can generate an equivalent data contract from a different type.

For example, these two data contracts are equivalent:

[DataContract] struct Contact { [DataMember] public string FirstName; [DataMember] public string LastName; ...
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.
Start your free trial

You might also like

Programming WCF Services, 3rd Edition

Programming WCF Services, 3rd Edition

Juval Lowy
Mastering ASP.NET Web API

Mastering ASP.NET Web API

Mithun Pattankar, Malendra Hurbuns

Publisher Resources

ISBN: 0596526997Supplemental ContentErrata Page