WCF Windows身份validation安全性错误

我有一些代码尝试模拟调用者的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 channel = new ChannelFactory(binding, endpoint); WCFTest.ConsoleHost.IService1 service = channel.CreateChannel(); return service.PrintMessage(msg); } 

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

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

有什么想法吗?

为了支持您的场景,您需要了解协议转换和约束委派的工作方式。 您需要配置Active Directory和WCF服务端点以支持此function。 请注意服务主体名称(SPN)的使用。 请查看以下链接,看看它们是否对您有所帮助。 本文提供了一个示例,演示了完成此工作所需的完整端到端配置。

如何:在Web应用程序的WCF调用中模拟原始调用方

同意marc_s这是双跳问题。

您需要一直通过Windows身份validation,因此:

  • 该请求必须在Windows用户的上下文中进行
  • 必须将IIS配置为使用Windows身份validation
  • 必须使用impersonate = true为Windows身份validation设置Web.config
  • 必须允许运行应用程序池的用户模拟用户。 这是双跳问题发生的常见地方。

有一个名为“认证后模拟客户端”的权利

http://blogs.technet.com/askperf/archive/2007/10/16/wmi-troubleshooting-impersonation-rights.aspx

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

我没有最终答案(我通常通过为需要调用其他服务的服务使用显式服务帐户来避免它)。

但是:你一定要查看CodePlex上的WCF安全指南并搜索“模拟” – 这里有很多文章解释了模仿原始调用者的所有细节以及为什么它很棘手。

如果您确定在两个跃点上都拥有正确的凭据,则可能导致该问题的下一个问题是缺少在端点上设置的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());