【发布时间】:2021-10-14 06:37:06
【问题描述】:
我正在使用客户端 PC 上的桌面应用程序与服务器上运行的 IIS WCF Web 服务进行通信,使用 WsHttpBinding 传递 Windows 用户凭据。该应用程序多年来一直运行良好,但现在我们正试图让它通过 HTTPS 而不仅仅是 HTTP 进行通信。
在服务器端,我们将 SSL 证书添加到 IIS 网站并更改 WCF web.config 以使用传输安全性进行绑定定义:
<wsHttpBinding>
<binding name="WSHttpBinding_IService1">
<readerQuotas maxArrayLength="2147483647" />
<security mode="Transport" />
</binding>
</wsHttpBinding>
在客户端,用于连接服务的客户端对象使用传输安全模式来说明 HTTPS 通信模式:
Dim serverURL as String = ReadServerURL()
Dim client As Service1Client
Dim binding As Channels.Binding
Dim dcso As ServiceModel.Description.DataContractSerializerOperationBehavior
binding = New WSHttpBinding("WSHttpBinding_IService1")
If serverURL.ToLower.StartsWith("https://") Then
CType(binding, WSHttpBinding).Security.Mode = SecurityMode.Transport
Else
CType(binding, WSHttpBinding).Security.Mode = SecurityMode.Message
End If
CType(binding, WSHttpBinding).Security.Message.ClientCredentialType = MessageCredentialType.Windows
CType(binding, WSHttpBinding).Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows
binding.ReceiveTimeout = New TimeSpan(0, 10, 0)
client = New Service1Client(binding, New EndpointAddress(serverURL))
client.ClientCredentials.Windows.ClientCredential = CType(CredentialCache.DefaultCredentials, NetworkCredential)
client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Delegation
一些客户使用 Kerberos 将 Windows 凭据传递到另一台服务器,这就是我们使用委托的原因。
大多数客户选择使用自签名证书,因为他们只使用内部服务器。
在 IIS 中,WCF 站点启用了 Windows 身份验证,同时启用了协商和 NTLM 提供程序。
这种方法在大多数客户网站上似乎都可以正常工作,但至少有一个网站遇到了这个错误:
HTTP 请求未通过客户端身份验证方案“协商”进行授权。从服务器收到的身份验证标头是 'Negotiate oXlwcKADCgEBomkEZ2..oZSQ='。
我不确定这个备用的“Negotiate oXlwcK...”提供程序在 IIS 中来自何处,或者如何配置客户端以与其正确通信。这是 IIS 配置问题、WCF 服务代码和/或客户端应用程序代码的问题,还是网络/域问题?非常感谢任何帮助。
【问题讨论】:
标签: .net wcf iis https wshttpbinding