Tuesday, July 18, 2006

Calling a Web Service by passing credentials

Here is the method I use for calling WebServices from my .Net applications. Usually from web services, we might need to pass the credentials of the logged in user to the webService also

public static MyWS.MyWSMethod GetMyWSMethod()
MyWS.MyWSMethod WS = new MyWS.MyWSMethod();
WS.Url = System.Configuration.ConfigurationSettings.AppSettings["MyWSURL"];
WS.PreAuthenticate = false;
WS.Credentials = System.Net.CredentialCache.DefaultCredentials;
return WS;

When PreAuthenticate = true, the WWW-authenticate header is sent with the first request if the authentication mechanism supports doing so. When PreAuthenticate = false, a request is made to the XML Web service method without initially attempting to authenticate the user. If the XML Web service allows anonymous access, then the XML Web service method is executed. If anonymous access is disallowed, a 401 HTTP return code is sent back to the client

When PreAuthenticate property to true, the NetworkCredential stored in the Credentials property will be sent to along with the resource request.


Anonymous Anonymous said...

Thank you for your explication !!

that s all right now !!!!


4:29 AM  
Anonymous Anonymous said...

Thanks for the help, i changed the authentication mode in 'windows' and now works.

Giuseppe from Rome Italy

3:33 AM  
Anonymous Anonymous said...

thank you very much

12:53 AM  
Anonymous Anonymous said...

Thanks, very helpful indeed. It's a shame it took a trip to Google to search for information the book missed... :(

9:14 PM  

Post a Comment

<< Home