c# - 使用 WSDualHttpBinding 在 WCF 服务之间共享 Windows 标识
问题描述
我在 IIS 7 中分别托管了两个 WCF 服务。第一个服务可从外部调用,并使用WebHttpBinding
Windows 身份验证。第二个服务仅由第一个服务调用,使用WsDualHttpBinding
.
当第一个服务被调用时,我可以从ServiceSecurityContext.Current.WindowsIdentity.Name
. 在第二项服务中,这不起作用,ServiceSecurityContext.Current.WindowsIdentity.Name
只是IIS APPPOOL\DefaultAppPool
.
我将其配置WsDualHttpBinding
为使用 Windows 身份验证,但这没有帮助。这是服务器端配置:
<wsDualHttpBinding>
<binding name="internalHttpBinding">
<security mode="Message">
<message clientCredentialType="Windows"/>
</security>
</binding>
</wsDualHttpBinding>
这是第一个服务中与第二个服务建立通信的代码:
private WSDualHttpBinding binding = new WSDualHttpBinding();
private ChannelFactory<IMyService> factory;
public IMyService Contract { get; set; }
public MyServiceCallback Callback { get; set; }
public MyService(Uri uri)
{
EndpointAddress address = new EndpointAddress(uri);
Callback = new MyServiceCallback();
var instanceContext = new InstanceContext(Callback);
binding.Security.Mode = WSDualHttpSecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
factory = new DuplexChannelFactory<IMyService>(instanceContext, binding, address);
factory.Credentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
factory.Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
Contract = factory.CreateChannel();
// Call operations on Contract
}
如何配置第一个服务以将用户的身份传递给第二个服务?
解决方案
这似乎是直通身份验证的问题。首先,您需要处于 Active Directory 环境中。必须使用 Kerberos 进行身份验证,NTLM 将不起作用。您可以使用 klist 进行检查: https ://docs.microsoft.com/en-us/windows-server/administration/windows-commands/klist
可能这篇SO文章可以提供帮助:
推荐阅读
- python - 为什么 swifter 比 vanilla df.apply 慢?
- python - 如何在 Jupyter Lab 中自定义键盘快捷键以运行当前行或选定文本?
- android - 向 Room Db 插入数据时出现 ConcurrentModificationException
- css - 如何删除导航栏上按钮之间的空格?
- c# - 如何对编号列表进行排序
- css - 由于溢出滚动触摸css,表响应“中断”模式内部
- android - Android:ConcurrentModificationException 错误
- python - PYTHON AUTH0 POST REQUEST:无效的请求负载 JSON 格式
- swift - 调用我自己的 API 到我的移动应用程序
- google-maps - 如何将热图添加到 Flutter 移动应用程序