确定WCF客户端ID [英] Identifying WCF Client ID

查看:167
本文介绍了确定WCF客户端ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个公开几个业务方法一个WCF Web服务。我也有两个客户 - 一个asp.net GUI和数据迁移应用程序,无论连接到后端WCF调用各种商业交易

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 backend to invoke various business transactions.

我需要我的后端能够识别和区分它们之间WCF客户端做出了一些变异逻辑的电话。

I need my backend to be able to identify and distinguish between which wcf client has made a call to some variant logic.

有没有办法,我的WCF服务能够识别连接到它的客户呢?也有使用签名的密钥,以prevent客户端从欺骗自己的身份的一种方式?

Is there a way that my WCF service is able to identify clients connected to it? Also is there a way to use a signed key to prevent a client from spoofing their identity?

推荐答案

您可以通过自定义页眉解决这个问题。

You can solve this via a custom header.

您可以添加自定义标题作为客户端应用程序的配置文件中的端点的一部分。这样,你会做每个客户的自定义标题不同。例如,在ASP.NET版本

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:

        <endpoint
            name="basicHttpEndpoint"
            address="http://localhost:8972"
            binding="basicHttpBinding"
            contract="MySeriveContractLib.IMyService"
            >
            <headers>
                <ClientIdentification>ASP_Client</ClientIdentification>
            </headers>
        </endpoint>

然后,服务可以检查头值,像这样:

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<string>(headerIndex);
   if clientString=="ASP_Client"
   {
       // ...
   }
   else
   {
      // ...
   }
}

这篇关于确定WCF客户端ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆