【问题标题】:The HTTP request is unauthorized with client authentication scheme Negotiate. The authentication header received from the server was Negotiate oX...Q=HTTP 请求未经客户端身份验证方案 Negotiate 授权。从服务器收到的身份验证标头是 Negotiate oX...Q=
【发布时间】: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


    【解决方案1】:

    我能够通过将UpnEndpointIdentity 对象添加到EndpointAddress 构造函数来解决此问题。

    对于UpnEndpointIdentity 中的参数,我必须使用显示在 IIS 应用程序池的“身份”列中的用户名。例如。 var id = new UpnEndpointIdentity("DOMAIN\user.name");

    这仅适用于 .NET Framework,但不适用于 .NET Core 3.1(我没有尝试 .NET Core 5.0)。

    【讨论】:

      【解决方案2】:

      如果您在调用同一台计算机上托管的 WCF 服务时看到此问题,您可能需要填充 BackConnectionHostNames 注册表项。

      1. 在 regedit 中,找到并单击以下注册表子项:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0

      2. 右键单击 MSV1_0,指向新建,然后单击多字符串值。

      3. 在“名称”列中,键入 BackConnectionHostNames,然后按 Enter。

      4. 右键单击 BackConnectionHostNames,然后单击修改。在数值数据框中,键入用于计算机上本地共享的 CNAME 或 DNS 别名,然后单击确定。

      在单独的行中键入每个主机名。

      详情请见Calling WCF service hosted in IIS on the same machine as client throws authentication error

      【讨论】:

      • 感谢您的回复,尽管在我们的情况下,客户端应用程序在托管 WCF 服务的同一台机器上运行良好,但不能从单独的客户端站运行。
      • 我建议你为此打开support ticket,微软工程师会帮助找到根本原因。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-02
      • 1970-01-01
      • 2013-03-12
      • 2021-12-27
      • 2018-12-10
      相关资源
      最近更新 更多