在WCF中,有没有办法省略/隐藏ServiceOperation或从WSDL一个数据成员?没有办法、成员、数据、WCF

2023-09-04 11:49:15 作者:奇葩向阳朵朵开

我有一个现有的WCF服务。在某些时候,有时一个 [OperationContract的] [数据成员] 在数据契约变成 [作废] 。我并不想删除的方法,回病房兼容的原因。另一个例子是,有时我有一个枚举,并希望 [作废] 的选择之一,但我不能完全去除它,因为项目在系统中已经存在/数据库包含该值

反正是没有办法省略生成的WDSL某些项目?例如:

  [的ServiceContract]
公共接口IMyService
{
    [OperationContract的]
    字符串的someMethod(字符串x); //我想这在WSDL

    [作废]
    [OperationContract的]
    字符串OldMethod(字符串x); //我不希望这样的WSDL,但我希望它仍然可以工作/可调用的,如果一个较旧的系统尝试调用它。
}
 

解决方案

有没有什么出位的现成它可以用来做,但你可以用一个WSDL出口延伸,除去一些操作从服务元数据。我实现了这个场景样品,在http://blogs.msdn.com/b/carlosfigueira/archive/2011/10/06/wcf-extensibility-wsdl-export-extension.aspx.

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.

WCF初探11 WCF客户端异步调用服务

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.
}

解决方案

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.