世界碳基金:由于身份验证失败,无法满足对安全令牌的请求
-
08-07-2019 - |
题
我在同一台机器上有两个 WCF 服务。一位是发布者,一位是聆听者。
发布者根据端点动态创建代理。我正在这样的代码中配置代理:
WSHttpBinding binding = new WSHttpBinding(SecurityMode.Message, true);
binding.Security.Message.NegotiateServiceCredential = true;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
binding.Security.Message.EstablishSecurityContext = true;
binding.ReliableSession.Enabled = true;
binding.TransactionFlow = true;
return binding;
进而...
Binding binding = GetBindingFromAddress(address);
ChannelFactory<T> factory = new ChannelFactory<T>(binding);
factory.Credentials.UserName.UserName = "an account on the machine";
factory.Credentials.UserName.Password = "a password for that account";
T proxy = factory.CreateChannel(new EndpointAddress(address));
当我去拨打电话时,我收到上述错误。这是我的监听器配置文件:
<service behaviorConfiguration="MEX Enabled" name="InvoiceSubscriber">
<endpoint binding="wsHttpBinding"
bindingConfiguration="ReliableTransactionalHTTP"
contract="AtlanticBT.SubscriptionService.Contracts.v1.IAtlanticEvents">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<bindings>
<wsHttpBinding>
<binding name="ReliableTransactionalHTTP" transactionFlow="true">
<reliableSession enabled="true"/>
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
我已经检查了托管服务的目录上的所有 ACL,它们似乎是正确的。IIS 安全性设置为匿名访问和 Windows 身份验证。
因此,如果我在代码中显式设置凭据,为什么我的侦听器无法进行身份验证?
解决方案
首先,此消息通常意味着计算机不在同一域中,因此无法使用 Windows 安全性进行通信。两台服务器是否在同一个域中?
其次,您已将端点配置为使用 Windows 安全性。您不仅在消息级别使用 Windows 安全性,而且还在传输级别使用 Windows 安全性。两者似乎都太过分了,你可能只是想进行运输。
第三,您配置的所有内容都显示“我想使用 Windows 身份验证”,但是您正在设置 ClientCredentials 的 UsernameClientCredentials 属性。这些属性仅用于用户名令牌安全,而不用于 Windows。Windows 安全性将获取当前线程的标识并将其转发。
假设您的意图是使用 Windows 安全性,那么您需要:
- 在您希望它与订阅者通信的单个 Windows 标识下运行您的发布者进程。
- 在发布者进程中使用模拟来更改每个调用的安全上下文(查看 WindowsIdentity.Impersonate 了解更多信息)
现在,从技术上讲,即使您认为通过设置用户名/密码属性正在执行#2,因为它们会被忽略,但您实际上正在执行#1。
最后,这里有一些关于如何为不同类型的 Windows 身份验证方案设置绑定的优秀文档:
除此之外,如果没有您提供更多信息,我不确定我还能提供什么。如果您修改您的问题以提供更多信息/回答我的一些问题,我将很乐意修改我的答案以使其更有用。
不隶属于 StackOverflow