Mark deprecated fields in WCF contract
Asked Answered
Q

3

9

I have a wcf contract that works with client v1.

Now I'm working on service v2, and i want to mark some of the fields as deprecated, So client v1 will see and use them, and client v2 will ignore them.

Are there any best practices for this issue? Are there any existing attributes in WCF that i should use?

thanks.

Quandary answered 23/3, 2011 at 11:57 Comment(0)
L
14

You can decorate your old properties as [Obsolete] but the client will only see them if they use a DLL reference and not service/web reference (WSDL). [Obsolete] decoration will not be passed to the client that uses WSDL to generate the proxy.

In terms of WCF versioning, once you have published an interface, you cannot remove any methods or in terms of contract you should really not remove any properties. You can publish a new interface and create a separate DTO class if you want new clients to use them.

Ref: Obsolete Attribute.

Landmeier answered 23/3, 2011 at 12:2 Comment(3)
The [Deprecated] is a custom property that you've created right?Quandary
Sorry I meant [Obsoltete]. Corrected it.Landmeier
[obsolete] won't leave me the option to support v1Quandary
S
0

On our side we usually version the operatiom via namespace. When an operation is deprecated we just put a deprecation comment in the description which the client can see through the wsdl. We notify our clients and let them know about the deprecated operations and when its expiration date is going to be.

Sulfanilamide answered 23/3, 2011 at 12:15 Comment(0)
K
0

I agree with @Aliostad that you shouldn't remove operations from the service contract in general as it introduces breaking change and as such should be avoided in single version of API.

However, if you want to inform client/consumer about some planned changes or have any other need to add certain "extra" information to the operation contract, you might take a look at IWsdlExportExtension interface, create a custom attribute that implements it and annotate particular operations.

You may take a look at this article for detailed reference.

Katy answered 30/1, 2017 at 20:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.