如何将凭据传递到SOAP Web服务? [英] How to pass credentials to a SOAP webservice?
本文介绍了如何将凭据传递到SOAP Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试调用SOAP Web服务,但是出现错误:附加信息:未提供用户名.在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是只读的.那么我该如何继续传递这些信息以访问Web服务?
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>
推荐答案
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 Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文