WCF – Data Contract version round-tripping using IExtensibleDataObject

Yan Cui

I help clients go faster for less using serverless technologies.

With WCF, provided that you’re using the DataContractSerializer and not the NetDataContractSerializer, you have a certain degree of protection against data contract changes from the client’s perspective.

Existing contracts will still work if existing members are not removed from the data contract, which means you are free to add new members to the data contract on the server side without affecting existing clients. This gives you some backward compatibility and allows you to incrementally evolve your data contracts in a non-breaking way.

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 your type must implement the IExtensibleDataContract interface and add the ExtensionData property of ExtensionDataObject type (see the MSDN article in the References section for an example).

It’s worth noting that the data stored in the ExtensionData property is not public retrievable and is only used by the WCF infrastructure.

And finally, to turn it off:

The round-tripping feature may be turned off, either by setting ignoreExtensionDataObject to true in the DataContractSerializer constructor or by setting theIgnoreExtensionDataObject property to true on the ServiceBehaviorAttribute. When this feature is off, the deserializer will not populate the ExtensionData property, and the serializer will not emit the contents of the property.

References:

MSDN article on Forward-Compatible Data Contracts

MSDN article on Best Practices on WCF Data Contract Versioning

MSDN – WCF Guildelines and Best Practices


 

Whenever you’re ready, here are 4 ways I can help you:

  1. If you want a one-stop shop to help you quickly level up your serverless skills, you should check out my Production-Ready Serverless workshop. Over 20 AWS Heroes & Community Builders have passed through this workshop, plus 1000+ students from the likes of AWS, LEGO, Booking, HBO and Siemens.
  2. If you want to learn how to test serverless applications without all the pain and hassle, you should check out my latest course, Testing Serverless Architectures.
  3. If you’re a manager or founder and want to help your team move faster and build better software, then check out my consulting services.
  4. If you just want to hang out, talk serverless, or ask for help, then you should join my FREE Community.

 


Leave a Comment

Your email address will not be published. Required fields are marked *