c# – WCF Windows身份验证安全性错误

前端之家收集整理的这篇文章主要介绍了c# – WCF Windows身份验证安全性错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一些代码尝试模拟调用者的 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);
}

但我得到错误
“呼叫者未通过该服务进行身份验证”
System.ServiceModel ….无法满足安全令牌的请求,因为身份验证失败…

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

有什么想法吗?

解决方法

为了支持您的场景,您需要了解 Protocol TransitionConstrained Delegation的工作原理.您需要配置Active Directory和WCF服务端点以支持功能.请注意服务主体名称(SPN)的使用.请查看以下链接,看看它们是否对您有所帮助.本文提供了一个示例,演示了完成此工作所需的完整端到端配置.

How To: Impersonate the Original Caller in WCF Calling from a Web Application

原文链接:https://www.f2er.com/csharp/99918.html

猜你在找的C#相关文章