gpt4 book ai didi

c# - WCF:无法满足对安全 token 的请求,因为身份验证失败

转载 作者:行者123 更新时间:2023-11-30 13:16:15 25 4
gpt4 key购买 nike

我在同一台机器上有两个 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 身份验证”,但是您正在设置 ClientCredentials 的 UsernameClientCredentials 属性。这些属性仅用于用户名 token 安全性,不适用于 Windows。 Windows 安全性将获取当前线程的标识并将其转发。

假设您打算使用 Windows 安全性,那么您需要:

  1. 在您希望它与订阅者进行通信的单一 Windows 身份下运行您的发布者进程。
  2. 在发布者进程中使用模拟来更改每个调用的安全上下文(查看 WindowsIdentity.Impersonate 了解更多信息)

现在您在技术上做的是#1,即使您认为通过设置用户名/密码属性做的是#2,因为它们被忽略了。

最后,这里有一些关于如何为不同类型的 Windows 身份验证场景设置绑定(bind)的好文档:


除此之外,如果没有您提供的更多信息,我不确定还能提供什么。如果您修改问题以提供更多信息/回答我的一些问题,我会很乐意修改我的答案,希望它更有用。

关于c# - WCF:无法满足对安全 token 的请求,因为身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1639035/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com