2011-02-09 13 views
5

WSDLに指定された認証要求が でないWSDLサービスに認証ヘッダーを送信しようとしています。SOAPにBasic Authヘッダーを追加するにはどうすればよいですか?

Webサービスの呼び出しに認証ヘッダーを追加するにはどうすればよいですか?私が取り組んできました

コード:この問題は、他のリンクではなく、ユーザー/パスワードの質問を含むWSDLに関連するさまざまな方法で疑問視されて

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での認証を要求していない可能性があることに気付いただけです。それについてもっと読んでください。 –

答えて

12

link

彼らは、同じ質問はありませんが、問題が関連しています。

Michaelis.MockServiceはWebserviceライブラリであり、これを行う方法の例が表示されます:link Mono project website。

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(); 
関連する問題