我有一些代码尝试模拟调用者的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凭证。
任何想法为什么?
答案 0 :(得分:3)
为了支持您的方案,您需要了解Protocol Transition和Constrained Delegation的工作原理。您需要配置Active Directory和WCF服务端点以支持此功能。请注意服务主体名称(SPN)的使用。请查看以下链接,看看它们是否对您有所帮助。本文提供了一个示例,演示了完成此工作所需的完整端到端配置。
How To: Impersonate the Original Caller in WCF Calling from a Web Application
答案 1 :(得分:1)
同意marc_s这是双跳问题。
您需要一直通过Windows身份验证,因此:
有一项名为“认证后模拟客户端”的权利
http://blogs.technet.com/askperf/archive/2007/10/16/wmi-troubleshooting-impersonation-rights.aspx
答案 2 :(得分:0)
冒充您服务到下一个是一个棘手的问题,称为“双跳”问题。
我没有最终答案(我通常通过为需要调用其他服务的服务使用显式服务帐户来避免它。)
但是:你一定要查看CodePlex上的WCF Security Guidance并搜索“模拟” - 这里有很多文章解释了冒充原始来电者的所有细节以及为什么它很棘手。 / p>
马克
答案 3 :(得分:0)
如果您确定在两个跃点上都拥有正确的凭据,则可能导致该问题的下一件事是缺少在端点上设置的EndpointDnsIdentity。
DnsEndpointIdentity identity = new DnsEndpointIdentity("localhost"); // localhost is default. Change if your service uses a different value in the service's config.
Uri uri = new Uri("net.tcp://serverName:9990/TestService1");
endpoint = new EndpointAddress(uri, identity, new AddressHeaderCollection());