开发者

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜