[英]How to pass credentials to a SOAP webservice?
I am trying to call a SOAP webservice, however I am getting the error: Additional information: The username is not provided.我正在尝试调用 SOAP 网络服务,但出现错误:附加信息:未提供用户名。 Specify username in ClientCredentials.
在 ClientCredentials 中指定用户名。
So I thought I could just set client.ClientCredentials to a new instance of NetworkCredentials.所以我想我可以将 client.ClientCredentials 设置为 NetworkCredentials 的新实例。 However ClientCredentials is read only.
但是 ClientCredentials 是只读的。 So how can I go about passing this information on to access the web service?
那么我如何才能将这些信息传递给访问 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();
EDIT: Binding:编辑:绑定:
<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 :您需要在客户端上设置凭据,如这篇 MSDN 文章所示:
client.ClientCredentials.UserName.UserName = "my_user_name";
client.ClientCredentials.UserName.Password = "my_password";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.