1
我使用ServiceDescriptionImporter從wsdl動態生成一個Web服務客戶端(運行時)。將HTTP頭添加到HttpSoapClientProtocol
一切工作很好,直到我嘗試調用需要身份驗證(基本)的服務。我無法找到任何方法將基本身份驗證標頭添加到由我生成的客戶端發送的請求中。
我已經嘗試了以下,但它不起作用。我仍然得到一個401:
var webClient = obj as HttpSoapClientProtocol;
CredentialCache mycache = new CredentialCache();
// Credentials are specified here
mycache.Add(new Uri("http://localhost:9999/MyService"), "Basic", new NetworkCredential("username", "password"));
webClient.Credentials = mycache;
如何添加HTTP頭到webClient(HttpWebClientProtocol)?
/Andreas