Search content within the blog

Thursday, August 5, 2010

Use of ignoreExtensionDataObject in WCF

In wcf we can chnage the existing datacontarcts and yet maintain compatability with old clients with the help of extensiondata object genereated
in the proxy.Below is an example that describes it and also explains the use of dataContarctSeralizer ignoreExtensionDataObject,

In wcf we can change the existing data contratcs as per new needs . The chnages can be classified as breaking chnages and
non-breaking chnages.

Nonbreaking Changes

Two types of changes will not break compatibility with existing clients:
• Adding new nonrequired data members
• Removing existing nonrequired data members

Breaking Changes
Change the name or namespace of a data contract.
• Rename an existing data member that was previously required.
• Add a new data member with a name that has been used previously.
• Change the data type of an existing data member.
• Add new members with isrequired = true Datamemberattribute
• Remove existing members with isrequired = true on Datamemberattribute.

Below we have two data contract definitions: The first is defined in a
V1 service, the second in the V2 version of that service. Notice that between
V1 and V2, the data member currency is removed and dailyvolume is
added. This change is nonbreaking.

[Datacontarct(Namespace = "http://stockservice")]
public class stockservice
[datamember] public double currentprice
[datamember] public Datetime currentime
[datamember] public string currency

[Datacontarct(Namespace = "http://stockservice")]
public class stockservice
[datamember] public double currentprice
[datamember] public Datetime currentime
[datamember] public string DailyVolume

For existing clients to properly pass around data after new members are added, the original data contract must support extensibility.
That is, the original contract must support serialization of unknown future data. This enables round tripping, where a client can
pass V2 data to a V1 service and have the V1 service return V1 data back to the client with the V2 elements still intact. WCF
implements extensibility by default in the proxy code generated by svcutil.exe. If you do not want to support this capability, it can be disabled
by specifying in the ServiceBehavior section of the service configuration file.

No comments:

Post a Comment