You must Sign In to post a response.
  • Category: WCF

    How to restrict methods in WCF service based on client


    Are you looking for a way to restrict methods in WCF service based on client ? then read this thread to know more about it



    How to restrict methods in WCF service based on client
  • #718413
    Hai Kali Raj,
    I didn't get your question fully? what do you mean by "restrict method" in WCF? Did you mean that the method which you have in WCFService should not be shown to the client? or the user who are consuming your WCF service? If yes, then you can have the methods without using the [Operation Contract] attribute. If you will not have the Operation Contract Attribute to your WCF service, that method will not be available to the clients who are consuming your service.
    e.g.

    [ServiceContract]
    public interface IDemoService
    {
    [OperationContract]
    void Show();
    void Add();
    }
    Here Add() method will not be visible to the client as it is not decorated with the [OperationContract] attribute.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #718425
    Hello Kali,

    As your question is not giving more information. This is how i am understanding .
    How to prevent the client by accessing service methods.

    There are two scenarios involved here

    scenario-1

    To hide a method to the outside world . if you are not going to give [OperationContract] to your webmethod it wont be appearing to the outside world

    Sample Code
    [ServiceContract]
    public interface Iemployeeservice
    {

    [OperationContract]
    string GetStudentName(int rollno);


    string GetStudentDetails(int rollname);

    }


    Scenario-2

    You want to expose both these methods to outside world and you want only certain clients to consume GetStudentName in this scenario
    You need to go infor additional authentication by getting the userid and pwd whenever the method is invoked.
    As both methods are in the same endpoint you have prevent the user only by this way or else you need to create a new service.




    Sample Code
    [ServiceContract]
    public interface Iemployeeservice
    {

    [OperationContract]
    string GetStudentName(int rollno,string uid,string pwd);

    [OperationContract]
    string GetStudentDetails(int rollname);

    }


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.