Wednesday, October 3, 2007

Let's Talk about .. Visual Studio 2005-Error Access Denied when calling Web Services

If you got the error message "Access Denied" when you called the Web Services, I suggest this method.

First, in Reference.cs, add the following command into the class of the Web Services that is referenced.
[C#]
this.PreAuthenticate = true;
this.Credentials = System.Net.CredentialCache.DefaultCredentials;
However, the senior colleague at my office told me that this method mostly works with VB.Net but not C#. So he recommended me to try the second method by set it as the Network Credential by assigning the username and password. (So, this one will okay when you have the username and password for the server that you call the web services)
[C#]
this.Credentials = new System.Net.NetworkCredential("username", "password");

No comments: