如何允许新客户端只访问WCF中的几个方法?

时间:2015-04-26 17:16:01

标签: wcf versions datacontracts

我有5个操作合同的WCF服务。假设200个用户使用此服务。 现在,新的50个客户端只需要来自此WCF服务的3个操作。

如何限制它们仅使用3并阻止其他2个操作?

1 个答案:

答案 0 :(得分:3)

您可能最好看一下基于角色的授权。这可以很容易地作为datacontract的属性实现。确定特定用户是否获得授权的实际逻辑完全取决于您的设计。

或者,您可以公开定义了不同接口的不同端点,并使用共享方法重用代码。

public Interface IInterface1
{
    void Method1(int something);
    void Method2(int something);
}

public Interface IInterface2
{
    void Method1(int something);
    void Method3(int something);
}

public InterfaceImplementation1 : IInterface1
{
    public void Method1(int something)
    {
        SharedClass.SharedMethod1(something);
    }

    public void Method2(int something)
    {
        SharedClass.SharedMethod2(something);
    }
}


public InterfaceImplementation2 : IInterface2
{
    public void Method1(int something)
    {
        SharedClass.SharedMethod1(something);
    }

    public void Method3(int something)
    {
        SharedClass.SharedMethod3(something);
    }
}


public class SharedClass
{
    public static void SharedMethod1 (int something)
    {
        DoSomething(something);
    }

    public static void SharedMethod2 (int something)
    {
        DoSomething(something);
    } 

    public static void SharedMethod3 (int something)
    {
        DoSomething(something);
    }
}
相关问题