Unauthorized or AccessDenied exception when using SOAP Native Xml Web Services

One of the common problems people face when using SQL 2005 web services for the first time is the requirement of specifying credentials in the SOAP request.  Unlike .Net Framework web services, where the server may not require credentials, SQL 2005 has a strict rule that credentials must be specified.

If your client application was developed using C# and you see the following exception:
   System.Net.WebException
The request failed with HTTP status 401: Unauthorized.

This means that the client application is not sending any credentials or the credentials are wrong (ie. old password).

To correct the problem, specify the correct credentials to be used.  The simplest way is to specify
   proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
in the C# code, where "proxy" is the variable of the web service class.

Additional information regarding how to specify the exact type of authentication scheme to use (ie. Digest, Kerberos, or NTLM) in a C# application is available in Books Online under topic "Specifying Non-Kerberos Authentication in Visual Studio Projects".  This topic is reachable through the index by looking for "Native XML Web Services"->"writing client applications".

If your client application was developed using C# and you see the following exception:
   System.Web.Services.Protocols.SoapException
There was an error in the incoming SOAP request packet: Client, LoginFailure, AccessDenied

This means that the user credential you specified does not have permission to connect to the endpoint or to execute the specific web method.

To correct the problem, grant the necessary permissions to the objects related to the request (ie. Connect permissions to the endpoint; execute permissions on the stored procedure; select permissions on the table; execute permissions CLR UDT; etc.)

Jimmy Wu, SQL Server Protocols
Disclaimer: This posting is provided "AS IS" with no warranties, and confers no rights