Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

wsdl

wcf

I have an existing WCF service. At some point, sometimes an [OperationContract] or a [DataMember] in a data contract becomes [Obsolete]. I don't want to remove the method, for back-wards compatibility reasons. Another example is sometimes I have an Enum, and want to [Obsolete] one of the choices, but I can't completely remove it because items already exist in the system / database that contain that value.

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

[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.
}
like image 475
CodingWithSpike Avatar asked May 18 '11 14:05

CodingWithSpike


2 Answers

There isn't anything out-of-the-box which can be used to do that, but you can use a WSDL export extension to remove some of the operations from the service metadata. I implemented a sample for this scenario at http://blogs.msdn.com/b/carlosfigueira/archive/2011/10/06/wcf-extensibility-wsdl-export-extension.aspx.

like image 59
carlosfigueira Avatar answered Sep 24 '22 02:09

carlosfigueira


WCF is pretty versioning tolerant within some constraints as documented in this MSDN article. It's probably too late for your current service to adopt some of these practices but you can accomplish what you want by creating new ServiceContract interfaces that remove the operations and enums you need hidden.

You would also need to create a new endpoint for the new the interface. The same service implementation can support multiple interfaces with a little tweaking so the changes shouldn't be too extensive. Any new clients would use the new service endpoint while the the old clients would use the original endpoint.

like image 30
Sixto Saez Avatar answered Sep 23 '22 02:09

Sixto Saez