Monday, September 3, 2007

.NET Web Service error - "The request failed with HTTP status 401: Access Denied."

This happen when try to call a Web service application and Anonymous access authentication is turned off.
You can solve this problem by using the Credentials property of the Web service client proxy to set the security credentials for Web service client authentication.
Assign the DefaultCredentials to the Credentials property of the Web Service Proxy class to call the Web service while Anonymous access authentication is turned off. See the following code:

  //Assigning DefaultCredentials to the Credentials property
  //of the Web service client proxy(ws)
  ws.Credentials = System.Net.CredentialCache.DefaultCredentials