wsHttpbinding与TransportWithMessageCredential和Windows身份验证

Sjb*_*ack 6 windows-authentication wshttpbinding transport-security

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

   <wsHttpBinding>
    <binding name="BindingName" .../>
      <security mode="TransportWithMessageCredential">
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </wsHttpBinding>   
Run Code Online (Sandbox Code Playgroud)

服务行为:

  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceCredentials>
       <userNameAuthentication userNamePasswordValidationMode="Windows" />
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>
Run Code Online (Sandbox Code Playgroud)

禁用匿名身份验证并启用Windows身份验证.

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

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

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

任何帮助表示赞赏.

Edw*_*ard 2

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

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

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

或者

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

<wsHttpBinding>
    <binding name="BindingName" .../>
      <security mode="Transport">
        <transport clientCredentialType="Ntlm" />
      </security>
    </binding>
  </wsHttpBinding>
Run Code Online (Sandbox Code Playgroud)