Identifying WCF Client ID

前端 未结 2 533
轻奢々
轻奢々 2020-12-10 07:03

I have a WCF web service that exposes several business methods. I also have two clients - an asp.net GUI and a data migration application that both connect to the wcf backen

2条回答
  •  时光取名叫无心
    2020-12-10 07:25

    You can solve this via a custom header.

    You can add a custom header as part of the endpoint in the client application's configuration file. You would then make each client's custom header different. For example, in the ASP.NET version:

            
                
                    ASP_Client
                
            
    

    Then the service can check the header value like so:

    public void MyServiceMethod()
    {
       var opContext = OperationContext.Current;
       var requestContext = opContext.RequestContext;
       var headers = requestContext.RequestMessage.Headers;
       int headerIndex = headers.FindHeader("ClientIdentification", "");
       var clientString = headers.GetHeader(headerIndex);
       if clientString=="ASP_Client"
       {
           // ...
       }
       else
       {
          // ...
       }
    }
    

提交回复
热议问题