WCF Windows身份验证安全性错误

7 c# asp.net wcf

我有一些代码尝试模拟调用者的Windows安全设置,然后连接到另一台机器上的另一个WCF服务

WindowsIdentity callerWindowsIdentity = ServiceSecurityContext.Current.WindowsIdentity;
using (callerWindowsIdentity.Impersonate())
{
    NetTcpBinding binding = new NetTcpBinding();
    binding.Security.Mode = SecurityMode.Message;
    binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
    EndpointAddress endpoint = new EndpointAddress(new Uri("net.tcp://serverName:9990/TestService1"));
    ChannelFactory<WCFTest.ConsoleHost.IService1> channel = new ChannelFactory<WCFTest.ConsoleHost.IService1>(binding, endpoint);
    WCFTest.ConsoleHost.IService1 service = channel.CreateChannel();
    return service.PrintMessage(msg);
}
Run Code Online (Sandbox Code Playgroud)

但是我收到错误:"调用者没有通过服务验证"System.ServiceModel ....由于身份验证失败,无法满足安全令牌的请求...

我试图模仿的凭据是服务所在框的valide windows凭证.

有什么想法吗?

mar*_*c_s 0

从您的服务冒充到下一个服务是一个棘手的问题,称为“双跳”问题。

我对此没有最终答案(我通常通过对需要调用另一个服务的服务使用显式服务帐户来避免它)。

但是:您绝对应该查看CodePlex 上的WCF 安全指南并搜索“模拟” - 那里有很多文章解释了模拟原始调用者的所有来龙去脉以及为什么它很棘手。

马克