Adding a DataMember to an existing DataContract in WCF

5k views Asked by At

I would like to add a DataMember to one of my DataContracts. I would like to know how existing servers and clients will behave in the presence of a new DataMember if one of the parties isn't updated.

I recall there is a way to make the DataMember optional, but I wonder if it would work in all scenarios:

  • updated Client => old Server
  • old Client => updated Server
  • updated Client <= old Server
  • old Client <= updated Server
1

There are 1 answers

1
Chris Wenham On BEST ANSWER

WCF will gracefully handle new members that it doesn't recognize. The consumer of the contract (on either the client or the server side) simply won't "see" that member, therefore a consequence is that the new member should never be an IsRequired=true property.

Furthermore, WCF will transparently bridge the new property between components as long as the DataContract implements IExtensibleDataObject. EG, if the message path goes:

updated client => old server => updated server

then the updated server on the end of the chain will still see the new DataMember. However, the "old server" will not see that new DataMember.

If an old server sends a message to an updated client, then the new DataMember will be set to default(type) upon deserialization in the new client.

There's more about Best Practices for DataContract versioning here.

And this article discusses the difference between Breaking and Non-Breaking changes.