服务器已拒绝客户端凭据 the server has rejected the client credentials

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sundacheng1989/article/details/83788953

我们的WinForm程序同构WCF与部署在服务器上的服务端相连。今天很多WinForm用户反映,在使用的时候遇到问题,抛出异常服务器已拒绝客户端凭据,the server has rejected the client credentials.

现在说一说WCF的安全认证问题。一般我们做的局域网应用,都没有加入任何的安全配置,那么WCF默认的安全配置是什么呢?如果不做任何安全配置,那么WCF采用Windows安全认证。默认等于做了如下配置:

<netTcpBinding>

  <binding name="netTcp">

    <security mode="Transport">

      <transport clientCredentialType="Windows" />

    </security>

  </binding>

</netTcpBinding>

经过查看,发现所有抛出异常的电脑,该用户在AD域中都被禁用了。WCF在服务端因为是Windows认证,所以发现这个用户有问题,就抛出了这个异常。当把AD域中的用户恢复以后,WCF也就正常了。

 

需要指出的是,还有可能的其他原因可以引发此异常,比如说WCF服务端需要impersonate客户端身份的时候,就需要客户端提供用户名密码,如果没有提供,也会抛出这个异常。

 

另外,如果对安全性要求没有那么高的话,我们可以禁用一切安全相关的设置,配置如下:

<bindings>

  <netTcpBinding>

    <binding name="customTcpBinding" maxReceivedMessageSize="20480000" transferMode="Streamed" >

      <security mode="None"></security>

    </binding>

  </netTcpBinding>

</bindings>

这样,就再不进行身份认证,也就再也不会抛出身份认证类似的异常了,只要相应的服务端IP与端口能访问,那么就可以正常调用。

 

https://stackoverflow.com/questions/53098405/wcf-throws-exception-that-the-server-has-rejected-the-client-credentials-what-i

https://stackoverflow.com/questions/8577612/the-server-has-rejected-the-client-credentials

猜你喜欢

转载自blog.csdn.net/sundacheng1989/article/details/83788953