在 WCF 中,有没有办法从 WSDL 中省略/隐藏 ServiceOperation 或 DataMember?

发布于 2024-11-08 05:59:42 字数 614 浏览 1 评论 0原文

我有一个现有的 WCF 服务。有时,数据协定中的 [OperationContract][DataMember] 会变成 [Obsolete]。出于向后兼容性的原因,我不想删除该方法。另一个例子是有时我有一个枚举,并且想要[Obsolete]其中一个选择,但我无法完全删除它,因为系统/数据库中已经存在包含该值的项目。

不管怎样,有没有办法从生成的 WDSL 中省略某些项目?例如:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

零時差 2024-11-15 05:59:42

没有任何开箱即用的东西可以用来执行此操作,但您可以使用 WSDL 导出扩展从服务元数据中删除一些操作。我在 http://blogs.msdn.com/b/卡洛斯菲盖拉/archive/2011/10/06/wcf-extensibility-wsdl-export-extension.aspx

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.

冷血 2024-11-15 05:59:42

WCF 在某些限制下具有很好的版本容忍度如这篇 MSDN 文章中所述。对于您当前的服务来说,采用其中一些实践可能为时已晚,但是您可以通过创建新的 ServiceContract 接口来删除您需要隐藏的操作和枚举来实现您想要的目的。

您还需要为新接口创建一个新端点。相同的服务实现只需稍加调整就可以支持多个接口,因此更改不应太大。任何新客户端都将使用新的服务端点,而旧客户端将使用原始端点。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文