In WCF, is there a way to omit / hide ServiceOperation or DataMember from WSDL?

I have an existing WCF service. At some point, sometimes [OperationContract] or [DataMember] in the data contract becomes [Obsolete] . I do not want to remove this method for compatibility reasons with previous versions. Another example - sometimes I have Enum and want [Obsolete] one of the options, but I cannot completely delete it, because the elements already exist in the system / database that contain this value.

Anyway, is there a way to omit certain elements from the generated WDSL? For instance:

 [ServiceContract] public interface IMyService { [OperationContract] string SomeMethod(string x); // I do want this in the WSDL [Obsolete] [OperationContract] string OldMethod(string x); // I do NOT want this in the WSDL, but I do want it to still work / be callable if an older system tries to call it. } 
+4
source share
2 answers

There is nothing that can be used for this, but you can use the WSDL export extension to remove some operations from service metadata. I applied the sample for this script at http://blogs.msdn.com/b/carlosfigueira/archive/2011/10/06/wcf-extensibility-wsdl-export-extension.aspx .

+5
source

WCF is fairly version-stable in some limitations as described in this MSDN article. It may be too late for your current service to accept some of these, but you can accomplish what you want by creating new ServiceContract interfaces that remove the operations and enumerations you need to hide.

You will also need to create a new endpoint for the new interface. The same service implementation can support several interfaces with a little customization, so the changes should not be too extensive. Any new clients will use the new service endpoint, while old clients will use the original endpoint.

+1
source

All Articles