【问题标题】:Expose different WSDL for different clients为不同的客户端公开不同的 WSDL
【发布时间】:2012-11-04 06:19:53
【问题描述】:

我开发了一个由三个 .NET Web 服务客户端使用的 WCF 应用程序。到目前为止一切顺利。

但现在我应该更改 WCF 应用程序,以便将不同的架构发布到不同的客户端。

例如:

class A : IMyServices
{
    public string GetName() {}

    public Order GetOrderInfo(string orderId) {}

    public Payment GetPaymentDetails(Order order) {}
}

我的一个客户不应该看到GetPaymentDetails(我基本上应该从那个客户创建的 WSDL 中隐藏这个 GetPaymentDetails 和 Payment 类模式)。其他客户端对其他方法会有限制。

在某些情况下,Payment 类的某些属性不应向客户端公开,即使它有权访问 GetPaymentDetails 操作。

有什么方法可以为不同的客户端公开不同的架构,并且我需要进行最少的更改?

要记住一件事:我的服务是使用 WCF 开发的,而使用我的服务的客户端使用传统的 .NET Web 服务。

【问题讨论】:

    标签: .net wcf web-services c#-4.0 wsdl


    【解决方案1】:

    如何拆分接口并为各种合约公开不同的端点(可能具有不同的安全性)?您可以按照以下思路设计合同和实施:

    [ServiceContract]
    public interface ICompleteService : IBasicService, IPaymentService
    { }
    
    [ServiceContract]
    public interface IBasicService
    {
        string GetName();
        Order GetOrderInfo(string orderId);
    }
    
    [ServiceContract]
    public interface IPaymentService
    {
        Payment GetPaymentDetails(Order order);
    }
    
    class A : ICompleteService
    {
        public string GetName() { }
        public Order GetOrderInfo(string orderId) { }
    
        public Payment GetPaymentDetails(Order order) { }
    }
    

    然后您可以根据需要公开端点,例如像这样:

    • 具有最低安全性的 IBasicService 端点
    • 具有最高安全性的 ICompleteService 端点

    您可以对 Payment DataContracts 采取类似的做法。合约负责确保不同的端点可以访问不同的操作和数据,而在后台它们将共享实现,从而最大限度地减少实现此功能所需的工作量。

    【讨论】:

    • 但我仍然不明白如何在一个类中为不同的客户控制属性..
    猜你喜欢
    • 2020-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-22
    • 1970-01-01
    • 2013-09-22
    • 2023-04-10
    • 1970-01-01
    相关资源
    最近更新 更多