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
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.
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.
4 Comments:
Thank you for your explication !!
that s all right now !!!!
chris
Thanks for the help, i changed the authentication mode in 'windows' and now works.
Giuseppe from Rome Italy
thank you very much
nu
Thanks, very helpful indeed. It's a shame it took a trip to Google to search for information the book missed... :(
Post a Comment
<< Home