How to add soap basic auth request to WSDL

Fernando André picture Fernando André · Feb 9, 2011 · Viewed 8.4k times · Source

How can I had soap AUTH BASIC auth to a WSDL, so who ever reads the WSDL knows I require that operation for a specific method ?

Answer

Fernando André picture Fernando André · Feb 10, 2011

Using the example bellow I have managed to pass the SOAP basic autentication to the php webservice on the other end. The PHP.net/Soapclient has a simple working example, but in csharp I found this link to be a solution to my problem.

link

Michaelis.MockService is the Webservice library extracted you may see an example on how to do this in: 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();