1

通过配置调用 netTcp 端点操作时是否可以冒充客户端的身份?WCF 配置客户端中有一个部分,如下所示:

<client>
    <endpoint 
        address="net.tcp://localhost:8081/tcpExample" 
        binding="netTcpBinding"
        bindingConfiguration="myTcpBinding" 
        contract="TestTcp.IHelloTcp"
        name="NetTcpBinding_IHelloTcp">
        <identity>
            <userPrincipalName value="leethax@mydomain.inc" />
        </identity>
    </endpoint>
</client>

我的客户端没有失败,似乎附加到客户端的身份是当前登录的用户,即我。

4

2 回答 2

3

你真的有三个选择:

  1. 手动模拟 (WindowsIdentity.Impersonate)
  2. 声明性模拟(OperationBehavior(Impersonation = Impersonation.Required))
  3. 完全模拟 (ServiceAuthorizationBehavior.ImpersonateCallerForAllOperations)

此外,请确保您运行服务的帐户(即 leethax@mydomain.inc)在计算机和域级别都被授予适当的权限。

于 2009-06-10T19:11:55.347 回答
1

嗯...不确定我是否跟随。netTcpBinding 的默认行为是使用 Windows 凭据 - 例如,您当前的 Windows 帐户用于服务凭据。

这是开箱即用的默认设置。

如果您想模拟其他用户,不,您不能在配置中执行此操作 - 您必须在代码中执行此操作。这是唯一的出路,对不起。

MyServiceClient client = new MyServiceClient();
client.ClientCredentials.Windows.ClientCredential.Domain = domain;
client.ClientCredentials.Windows.ClientCredential.UserName = username;
client.ClientCredentials.Windows.ClientCredential.Password = password;

在配置中指定不同用户的唯一方法是使用定义另一个要使用的用户帐户的证书。您不能在配置文件中配置直接的 Windows 用户帐户及其密码。

于 2009-06-10T14:39:14.757 回答