簡體   English   中英

如何將憑據傳遞給 SOAP 網絡服務?

[英]How to pass credentials to a SOAP webservice?

我正在嘗試調用 SOAP 網絡服務,但出現錯誤:附加信息:未提供用戶名。 在 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();

編輯:綁定:

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

您需要在客戶端上設置憑據,如這篇 MSDN 文章所示:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM