我正在尝试调用SOAP Web服务,但是出现错误:
附加信息:未提供用户名。在ClientCredentials中指定用户名。
所以我想我可以将client.ClientCredentials设置为NetworkCredentials的新实例。但是ClientCredentials是只读的。那么我该如何传递这些信息以访问Web服务呢?
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();
编辑:
bundle :
<binding name="VersionHttpBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" />
</security>
</binding>
最佳答案
您需要在客户端上设置凭据,如in this MSDN article所示:client.ClientCredentials.UserName.UserName = "my_user_name"; client.ClientCredentials.UserName.Password = "my_password";
关于c# - 如何将凭据传递到SOAP Web服务?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37120894/