0

I have WCF service with 5 operation contracts. Say 200 users using this service. Now new 50 clients want only 3 operations from this WCF service.

How do I restrict them to use only 3 and block other 2 operations ?

Razib
  • 10,965
  • 11
  • 53
  • 80
James
  • 1

1 Answers1

3

You are probably best off looking at some kind of role based authorization. This can be easily implemented as an attribute on the datacontract. The actual logic to determine as to whether that particular user is authorised is entirely by your design.

Alternatively, you can expose different endpoints that have a different interface defined and use shared methods for code re-use.

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);
    }
}
ChrisBint
  • 12,773
  • 6
  • 40
  • 62
  • Thanks Chris for your response. But i am not asking any perticular user here. I am saying if i have service say with operations say A, B, C, D, E and new clients ( may be 300 or 400 ) want to use only B,C, E then how do i restrict them to not use A, D? Also For the second answer given by you i thought of same approach but that may be repetitive means code will be repetitive . could you please provide any sample code for this ? – James Apr 26 '15 at 17:23
  • 1
    Example added. Simple define 2 endpoints, with 1 exposing IInterface1, and the other IInterface2 – ChrisBint Apr 26 '15 at 18:28