调用,需要从WCF客户端基本的HTTP身份验证的Web服务 [英] Calling a web service that requires basic http authentication from wcf client

查看:290
本文介绍了调用,需要从WCF客户端基本的HTTP身份验证的Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web服务的WSDL,我产生了WCF代理。没问题。

I have a wsdl from a web service, I generated the wcf proxy. No problem.

但我不能让我的头,围绕如何通过用户名和密码。该Web服务需要基本身份验证 - 只有用户名和密码

But I can not get my head around how to pass the user name and password. The webservice requires basic authentication - only username and password.

任何帮助吗?

推荐答案

被配置为配置文件中的基本身份验证?你需要传递唯一凭据或做你也需要安全的交通工具(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 = "...";

这篇关于调用,需要从WCF客户端基本的HTTP身份验证的Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆