0

When doing lax versioning in DataContract classes, the Best Practices: Data Contract Versioning guide states:

Do not change the IsRequired property on any existing data members from version to version.

But then the Data Contract Versioning guide states:

Changing the IsRequired property value from true to false is not breaking, but changing it from false to true may be breaking if any prior versions of the type do not have the data member in question.

The first guide says that IsRequired should never be changed, and then the second guide says changing from false to true is non-breaking.

How would you reflect that a property is no longer required in a later version of a contract? If I change IsRequired from true to false wouldn't that break clients who are using the earlier version? They would be able to omit the once required property. Would this kind of change require the introduction of a new contract?

1 Answer 1

1

When you change IsRequired from true to false, it means every caller are already using a value in the field. Removing the IsRequired is not gonna change anything for them, since they already include a value, thus 'not breaking'.

Your clients can then decide to keep sending the given value or omit it in the future version of their call to your WebService. In this case, I wouldn't use a new contract.

Sign up to request clarification or add additional context in comments.

6 Comments

But couldn't someone building an app using V1 of the API be able to send "null" to a required property? Even though the V1 documentation says the property is required, it would still accept null as a valid value for the previously required property and instead of rejecting the web service request the user would get a server error somewhere in the stack.
if you change it to IsRequired = false, it means that you deal with null value in your function. If you don't then leave it as IsRequired = true.
What if I changed it to IsRequired=false because the V2 service method handles a null value for that property and the V1 implementation of the service method expects a value for it?
In that case, you need a new contract, since you're not redefining your function. You could modify IsRequired = false and your function as an 'update' of the V1, not a completely new version. That's what they mean by 'non-breaking'
Does that answer your question? or do you need more clarifications about wcf versionning?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.