6

我有一个用于 wsHttpBinding 和 TransportWithMessageCredential 的 IIS 托管 WCF 服务,具有以下绑定配置(我从空间绑定中删除了所有属性)

   <wsHttpBinding>
    <binding name="BindingName" .../>
      <security mode="TransportWithMessageCredential">
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </wsHttpBinding>   

具有以下服务行为:

  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceCredentials>
       <userNameAuthentication userNamePasswordValidationMode="Windows" />
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>

匿名身份验证被禁用,Windows 身份验证被启用。

在客户端,使用有效的 Windows 用户和密码设置凭据,但每次调用服务时都会出现以下异常:

HTTP 请求未经客户端身份验证方案“匿名”授权。从服务器收到的身份验证标头是“协商,NTLM”。---> System.ServiceModel.Security.MessageSecurityException:HTTP 请求未经客户端身份验证方案“匿名”授权。从服务器收到的身份验证标头是“协商,NTLM”。---> System.Net.WebException:远程服务器返回错误:(401)未经授权。

使用 WCF 服务的自托管版本,它可以在有效的 Windows 帐户下正常运行。

任何帮助表示赞赏。

4

1 回答 1

2

在 IIS 中启用 Windows 身份验证需要在传输层提供凭据,而您的配置定义身份验证发生在消息层

要解决此问题,您需要执行以下操作之一

1) 在 IIS 中启用匿名访问,因为身份验证将在消息层处理

或者

2) 将您的安全模式更新为传输

<wsHttpBinding>
    <binding name="BindingName" .../>
      <security mode="Transport">
        <transport clientCredentialType="Ntlm" />
      </security>
    </binding>
  </wsHttpBinding>
于 2014-09-10T11:00:55.917 回答