Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a DataMember to an existing DataContract in WCF

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
like image 321
Jader Dias Avatar asked Apr 11 '11 16:04

Jader Dias


1 Answers

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.

like image 180
Chris Wenham Avatar answered Oct 24 '22 16:10

Chris Wenham