且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

调用,需要从WCF客户端基本的HTTP身份验证的Web服务

更新时间:2023-09-13 14:31:40

被配置为配置文件中的基本身份验证?你需要传递唯一凭据或做你也需要安全的交通工具(HTTPS)?

Is Basic authentication configured in configuration file? Do you need to pass only credentials or do you also need secured transport (HTTPS)?

首先,您需要设置绑定,支持基本身份验证

First you need to set up binding to support Basic authentication

设置为HTTP绑定:

<bindings>
  <basicHttpBinding>
    <binding name="BasicAuth">
      <security mode="TransportCredentialOnly">
        <transport clientCredentialType="Basic" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

设置为HTTPS绑定:

Setup for HTTPS binding:

<bindings>
  <basicHttpBidning>
    <binding name="BasicAuthSecured">
      <security mode="Transport">
        <transport clientCredentialType="Basic" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

客户端的端点必须使用定义的配置,如:

Client endpoint has to use defined configuration like:

<client>
  <endpoint address="..." 
            name="..." 
            binding="basicHttpBinding" 
            bindingConfiguration="BasicAuth" 
            contract="..."  />
</client>

然后,你必须传递凭据到代理:

Then you have to pass credentials to the proxy:

proxy = new MyServiceClient();
proxy.ClientCredentials.UserName.UserName = "...";
proxy.ClientCredentials.UserName.Password = "...";