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 3 ways I can help you:

  1. Production-Ready Serverless: Join 20+ AWS Heroes & Community Builders and 1000+ other students in levelling up your serverless game. This is your one-stop shop for quickly levelling up your serverless skills.
  2. I help clients launch product ideas, improve their development processes and upskill their teams. If you’d like to work together, then let’s get in touch.
  3. Join my community on Discord, ask questions, and join the discussion on all things AWS and Serverless.

Leave a Comment

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