如何将凭据传递到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>