本文介绍了如何将凭据传递给 SOAP 网络服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调用 SOAP 网络服务,但出现错误:附加信息:未提供用户名.在 ClientCredentials 中指定用户名.

I am trying to call a SOAP webservice, however I am getting the error:Additional information: The username is not provided. Specify username in ClientCredentials.

所以我想我可以将 client.ClientCredentials 设置为 NetworkCredentials 的新实例.但是 ClientCredentials 是只读的.那么我怎样才能将这些信息传递给访问网络服务呢?

So I thought I could just set client.ClientCredentials to a new instance of NetworkCredentials. However ClientCredentials is read only. So how can I go about passing this information on to access the web service?

    myService.ServiceClient client = new myService.ServiceClient();
    // This won't work since its read only.
    client.ClientCredentials = new System.Net.NetworkCredential("username", "password", "domain");
    string version = client.getData();

绑定:

  <binding name="VersionHttpBinding">
    <security mode="TransportCredentialOnly">
      <transport clientCredentialType="Basic" />
    </security>
  </binding>

推荐答案

您需要在客户端上设置凭据,如下所示 在这篇 MSDN 文章中:

You'll need to set the credentials on the client, like as shown in this MSDN article:

client.ClientCredentials.UserName.UserName = "my_user_name";
client.ClientCredentials.UserName.Password = "my_password";

这篇关于如何将凭据传递给 SOAP 网络服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-10 08:15