Mark deprecated fields in WCF contract

2019-06-16 20:43发布

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.

3条回答
三岁会撩人
2楼-- · 2019-06-16 21:02

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.

查看更多
做个烂人
3楼-- · 2019-06-16 21:09

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.

查看更多
Luminary・发光体
4楼-- · 2019-06-16 21:12

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.

查看更多
登录 后发表回答