Problem: Accessing web service causes exception – “The request failed with
HTTP status 401 : Access Denied”.
I created a web service on my local machine and then developed a separate
test solution (windows app) to test it. The above mentioned exception occurs
when program executes a call to a function in web service.
I created another simple web service that has only one method, HelloWorld.
Then I used the test application to call the HelloWorld function and still
got the same exception.
I can use the IE to successfully get the response from the web service.
I added <identity impersonate="true" /> to web.config but nothing changed.
Does anyone has an idea what is missing?
Thanks.
Mujtaba Syed - 21 Dec 2004 17:59 GMT
Hi:
Enable anonymous authentication in IIS for your web service.
This question has been asked and answered a couple of times in the last week
or so on this and the microsoft.public.dotnet.framework.aspnet.webservices
group. It's a good habit to look at the previous post for questions similar
to your that have got answers before posting your question. :-)
Thank you,
Mujtaba.
> Problem: Accessing web service causes exception - "The request failed with
> HTTP status 401 : Access Denied".
[quoted text clipped - 8 lines]
> Does anyone has an idea what is missing?
> Thanks.
Tom Porterfield - 21 Dec 2004 18:19 GMT
> Problem: Accessing web service causes exception – “The request failed with
> HTTP status 401 : Access Denied”.
[quoted text clipped - 8 lines]
> Does anyone has an idea what is missing?
> Thanks.
Do you have your virtual directory in IIS setup for anonymous access? IE
will automatically send security credentials if the zone is intranet or
computer. If you want security credentials to be passed to a webservice
from within your code, you must set them. The following example should
work:
webServiceProxy.Credentials =
System.Net.CredentialCache.DefaultCredentials;

Signature
Tom Porterfield
Khalique - 21 Dec 2004 19:21 GMT
Thanks Mujtaba and Tom.
Setting credentials solved the problem.
Mujtaba, I did not want to allow Anonymous Access and that is why I had
disabled that. And I looked for an answer in the previous posts in last few
days. However, I did not go back before 16 of this month.
Thanks a lot for your valuable help
Khalique.
> > Problem: Accessing web service causes exception – “The request failed with
> > HTTP status 401 : Access Denied”.
[quoted text clipped - 17 lines]
> webServiceProxy.Credentials =
> System.Net.CredentialCache.DefaultCredentials;