access denied on a web service

E

Edward W.

I wrote my web service and I have no problem browsing to the asmx file and
seeing the public methods. I can even invoke them with no problem. But in
my asp.net application I get this error message "The request failed with
HTTP status 401: Access Denied. "

BUT when I add this line to my code it works fine.

gsdiApplication gsdiWebService = new gsdiApplication();
gsdiApplication.Credentials =
stem.Net.CredentialCache.DefaultCredentials; ------ when I add this line
it then works!
gsdiApplication.....
<code here>
gsdi.Dispose();



But I don't understand why I needed to add it? I never had to do anything
like that before. What required it this time?

Ed
 
G

Guest

The short answer is because your web site demands it.

But to be a little less terse, the virtual directory in which your web
service is running has anonymous access turned off. This means that, in
order to access a page in that directory, credentials are required. If you
had hit a page with a browser, then behind the scenes the browser would have
received a request for credentials and provided them. However, the proxy
class used to access a web service doesn't do that. Instead, you need to
provide them, something you're doing by setting the Credentials property. If
you would rather not do this, then turn anonymous access on on the virtual
directory.

Hope this helps.
 
E

Edward W.

thank you. I looked at it further today. What I did was go into internet
manager directly (windows xp pro) and create a new virtual directory for the
web service. Then I created the web service in VS.NET 2003 and pointed to
the URL of the virtual directory I had just created. When I go into the
properties of the virtual directory from within inetmgr, I see as the first
tab it's named "Virtual Directory."

Next I created a new solution and added a web service as a project but I let
VS.NET create the IIS directory. Then in inetmgr, I checked the properties
of the web service site and noticed the first tab is called just "Directory"
and also it has a Server Extensions tab.

So what I did differently than I normally had done was to create the IIS
directory first before I created the web service. I did this so I could
control where the files were, namely not in the inetpub\wwwroot folder.

So my question is, how can I create the directory manually first, and what
do I choose if I shouldn't choose "virtual directory"?

thanks
Ed



"Bruce Johnson [.NET MVP]" <Bruce Johnson [.NET
MVP]@discussions.microsoft.com> wrote in message
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top