Thursday, March 23, 2006

VS: Using Windows Authentication on a webservice called by an ASP.NET webapplication

It’s relatively simple to use the right authentication, but unfortunately mostly after you know it! Here are the steps to call a webservice with Windows Authentication:

1. Modify the web.config of the ASP.NET webapplication:
<authentication mode="Windows" />
<identity impersonate="true" />

2. Modify the web.config of the webservice:
<authentication mode="Windows" />
<authorization>
<allow users="Administrator" />
<deny users="*" />
</authorization>

3. Disable anonymous authentication in IIS for the ASP.NET webapplication and the webservice

4. Before calling the webservice set the credentials
localhost.Service1 srv= new WebAppTest.localhost.Service1();
srv.Credentials = System.Net.CredentialCache.DefaultCredentials;
srv.WebserviceFunction();


Good luck!

No comments: