Shaggydog
Shaggydog

Reputation: 3798

Do I need to update a WCF service reference if I'm only adding to the contract?

I have an old WCF service project (on .NET Framework 4.8), and a client that uses it. I need to extend a service method with a new parameter. Problem is, there are other clients that are using this service, and I'm trying to avoid having to modify those. I was thinking of doing this in a way that wouldn't affect other clients - no changes, just additions. But then I realized just the fact that I made changes to the service contract might be enough to require an update of the client's reference - even if they are not breaking changes.

I was thinking of either

a) Adding a new optional parameter to the end of an existing method:

 [OperationContract(Name = "ExistingMethod")]
 List<ResponseObject> ExistingMethod(int? p1, int? p2, int? p3, ... int? newParameter = null);

or b) creating a new method that's identical to the old one, except it has the extra parameter

[OperationContract(Name = "NewMethod")]
List<ResponseObject> NewMethod(int? p1, int? p2, int? p3, ... int? newParameter = null);

Would any of these approaches work? Would those other clients still be able to use the service, or would I have to update the service reference for those clients as well?

Upvotes: 0

Views: 183

Answers (1)

Jiayao
Jiayao

Reputation: 578

If all you're doing is adding functionality instead of modifying it, and the client doesn't use the new functionality, there's no impact on the client's usage and you don't need to update the service reference.

Changing a property from non-null to null in a service contract or changing the property of a data member requires the service reference to be updated or it will break.

Upvotes: 0

Related Questions