2011-02-09 27 views
5

我試圖將驗證標頭髮送到WSDL服務,該服務沒有在WSDL上指定的驗證要求 。如何添加基本驗證標題到我的SOAP?

如何將Auth頭添加到Web服務的調用中?

代碼我一直努力着:

using System; 
using System.Web.Services.Protocols; 

namespace TesteSoap 
{   
    class MainClass 
    { 
     public static void Main (string[] args) 
     { 

      WSDLService Service = new WSDLService(); 
      /* How can I add authentication to the call of this webservice ? */ 
      Service.get(); 
      Console.WriteLine ("Hello World!"); 
     } 
    } 
} 
+0

只注意到問題可能是我沒有請求WSDL中的授權。必須閱讀更多。 – 2011-02-09 15:43:21

回答

12

這個問題在其他鏈接,但在涉及到WSDL包括用戶名/密碼的問題以不同的方式提出質疑。

link

他們是不一樣的問題,但這個問題有關。

Michaelis.MockService是提取的Webservice庫,您可能會看到如何在如下項目中執行此操作的示例:link Mono項目網站。

Michaelis.MockService service = new Michaelis.MockService(); 

// Create the network credentials and assign 
// them to the service credentials 
NetworkCredential netCredential = new NetworkCredential("Inigo.Montoya", "Ykmfptd"); 
Uri uri = new Uri(service.Url); 
ICredentials credentials = netCredential.GetCredential(uri, "Basic"); 
service.Credentials = credentials; 

// Be sure to set PreAuthenticate to true or else 
// authentication will not be sent. 
service.PreAuthenticate = true; 

// Make the web service call. 
service.Method(); 
相關問題