具有 WsHttpBinding 和 windows 身份验证的 WCF 服务因匿名访问错误而失败

WCF service with WsHttpBinding & windows authentication failing with anonymous access error

美好的一天。我在 WCF 中编写了一个使用 message-level 安全性的服务,该服务设置为使用 Windows 身份验证。相关配置如下图:

<wsHttpBinding>
    <binding name="WsHttpBinding" closeTimeout="00:30:00" openTimeout="00:30:00"
      receiveTimeout="00:30:00" sendTimeout="00:30:00" maxBufferPoolSize="2147483647"
      maxReceivedMessageSize="2147483647">
      <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647"
        maxBytesPerRead="2147483647" />
      <security mode="Message">
        <message clientCredentialType="Windows" establishSecurityContext="true" />
      </security>
    </binding>
</wsHttpBinding>

调用客户端的开发人员要求使用这些详细信息配置我的服务。不幸的是,我也无法访问客户端绑定的配置,但我只能假设它配置正确,因为它使用的其他服务正在运行。

该服务通过 IIS 托管,作为默认网站下的应用程序。服务应用程序的身份验证设置为 Windows,匿名身份验证已关闭。它也没有绑定 SSL 证书。

当从客户端调用服务时,日志中会报告以下错误: HTTP 请求未经客户端身份验证方案 'Anonymous' 授权。从服务器收到的身份验证 header 是 'Negotiate,NTLM'。

如果能帮助解决这个问题,我们将不胜感激。

附加信息

为了寻找解决方案,我拼凑了一个 WinForms 测试客户端来调用该服务。客户端绑定配置如下:

<wsHttpBinding>
    <binding name="WSHttpBinding_IEAIEndpointService" closeTimeout="00:10:00"
      openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
      maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
        <security mode="Message">
          <message clientCredentialType="Windows" establishSecurityContext="true" />
        </security>
    </binding>
</wsHttpBinding>

在使用客户端代理进行调用之前,我有以下代码来设置 Windows 我希望服务验证的用户帐户:

client.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("Username", "Password", "DOMAIN");

即使使用此配置,我仍然收到 above-mentioned 错误。

IIS 身份验证是传输安全。您的客户要求消息安全,因此您需要禁用它。消息安全将由 WCF 而不是 IIS 处理。