【问题标题】:WCF client authentication on server side服务器端的 WCF 客户端身份验证
【发布时间】:2012-04-15 23:55:33
【问题描述】:

我的客户有这样的结构。

WindowsIdentity wi = WindowsIdentity.GetCurrent();
IntPtr token = wi.Token;

下一步是通过 WCF 将身份验证令牌发送到服务器并在那里模拟用户。

api.SendToken(token);

...
...
...

但是当我在服务器端收到令牌并尝试构建 WindowsIdentity 时,它会抛出一个错误:

WindowsIdentity newId = new WindowsIdentity(token);

Invalid token for impersonation - it cannot be duplicated.

请你们帮我找出我做错了什么并分享你的想法如何将令牌从客户端传递到服务器。

谢谢!

【问题讨论】:

标签: wcf authentication impersonation


【解决方案1】:

WCF 已经内置了支持Windows impersonation. 的管道,您尝试自己开发有什么原因吗?

更新以避免仅链接的答案(啊,我年轻时的错误......)

以下是配置内置 WCF 模拟所需的基本步骤

  • 只有某些绑定支持 Windows 身份验证。 WSHttpBinding 是最常见的支持它,但其他人也可能支持它。

  • 在服务契约上,在需要模拟的方法上使用 OperationBehavior 属性:

    [OperationBehavior(Impersonation=ImpersonationOption.Required)]
    public string SomeMethod(string aParameter) { ... }
    
  • 对于客户端,最简单的方法是创建一个继承自 ClientBase 类的自定义类。所有服务引用类型都继承自此类。以下是客户端代码示例:

    var client = new SomeClientBaseDerivedType("TheServiceEndpoint");
    client.ClientCredentials.Windows.AllowedImpersonationLevel =
        System.Security.Principal.TokenImpersonationLevel.Impersonation;
    

【讨论】:

    猜你喜欢
    • 2012-08-28
    • 2011-11-04
    • 1970-01-01
    • 2011-04-09
    • 2013-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多