0

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

我如何限制他们只使用 3 并阻止其他 2 操作?

4

1 回答 1

3

您可能最好查看某种基于角色的授权。这可以很容易地作为数据合同上的一个属性来实现。确定特定用户是否被授权的实际逻辑完全由您的设计决定。

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

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);
    }
}
于 2015-04-26T17:19:29.223 回答