With WCF, pro­vided that you’re using the Dat­a­Con­tract­Se­ri­al­izer and not the Net­Dat­a­Con­tract­Se­ri­al­izer, you have a cer­tain degree of pro­tec­tion against data con­tract changes from the client’s perspective.

Exist­ing con­tracts will still work if exist­ing mem­bers are not removed from the data con­tract, which means you are free to add new mem­bers to the data con­tract on the server side with­out affect­ing exist­ing clients. This gives you some back­ward com­pat­i­bil­ity and allows you to incre­men­tally evolve your data con­tracts in a non-breaking way.

Round-Tripping

Round-tripping occurs when data passes from a new ver­sion to an old ver­sion and back to the new ver­sion of a data con­tract. Round-tripping guar­an­tees that no data is lost. Enabling round-tripping makes the type forward-compatible with any future changes sup­ported by the data con­tract ver­sion­ing model.

To enable round-tripping your type must imple­ment the IEx­ten­si­ble­Dat­a­Con­tract inter­face and add the Exten­sion­Data prop­erty of Exten­sion­DataOb­ject type (see the MSDN arti­cle in the Ref­er­ences sec­tion for an example).

It’s worth not­ing that the data stored in the Exten­sion­Data prop­erty is not pub­lic retriev­able and is only used by the WCF infrastructure.

And finally, to turn it off:

The round-tripping fea­ture may be turned off, either by set­ting ignore­Ex­ten­sion­DataOb­ject to true in the Dat­a­Con­tract­Se­ri­al­izer con­struc­tor or by set­ting theIgnore­Ex­ten­sion­DataOb­ject prop­erty to true on the Ser­vice­Be­hav­iorAt­tribute. When this fea­ture is off, the dese­ri­al­izer will not pop­u­late the Exten­sion­Data prop­erty, and the seri­al­izer will not emit the con­tents of the property.

Ref­er­ences:

MSDN arti­cle on Forward-Compatible Data Contracts

MSDN arti­cle on Best Prac­tices on WCF Data Con­tract Versioning

MSDNWCF Guilde­lines and Best Practices

Share

Leave a Reply