browse: forums | FAQ
Connecting Tech Pros Worldwide

Hey there! Do you need ASP.NET help?

Get answers from our community of ASP.NET experts on BYTES! It's free.

The request failed with HTTP status 401: Unauthorized

ad
Guest
 
Posts: n/a
#1: Feb 17 '06
I have a WebService in localhost, and the set in the web.config is

<add key="WebReference.Service"
value="http://localhost/HealthService/Service.asmx"/>
and the code to refer the WebService is
WebReference.Service wsHealth = new WebReference.Service();

But when I use code to execute a function in the webservice, like
ds =(System.Data.DataSet)wsHealth.GetSchools_Zip(txtZ ip1.Text);

it result into an error:
The request failed with HTTP status 401: Unauthorized


I have type the web service URL into browse, it execute OK, but it can't
call in program.

How can I do?






Brock Allen
Guest
 
Posts: n/a
#2: Feb 17 '06

re: The request failed with HTTP status 401: Unauthorized


Sounds like IIS is using integrated authentication for that application.
Your browser supplies the credentials of the logged in user, whereas the
web service proxy does not. You can either change the code for your web service
proxy to 1) hard code the credntials, 2) prompt the user and pass those credentials,
or 3) use the current logged in user's credentials. Check out the Credentials
property of teh web service proxy. Set it to CredentialCache.DefaultCredentials
to get the thrid behavior I listed. For the first or second, use an instance
of the System.Net.NEtworkCredential class.

-Brock
http://staff.develop.com/ballen

[color=blue]
> I have a WebService in localhost, and the set in the web.config is
>
> <add key="WebReference.Service"
> value="http://localhost/HealthService/Service.asmx"/>
> and the code to refer the WebService is
> WebReference.Service wsHealth = new WebReference.Service();
> But when I use code to execute a function in the webservice, like
> ds =(System.Data.DataSet)wsHealth.GetSchools_Zip(txtZ ip1.Text);
> it result into an error:
> The request failed with HTTP status 401: Unauthorized
> I have type the web service URL into browse, it execute OK, but it
> can't call in program.
>
> How can I do?
>[/color]


ad
Guest
 
Posts: n/a
#3: Feb 18 '06

re: The request failed with HTTP status 401: Unauthorized


Thanks,
I use the method 3, and my problem is gone away.
But I have some question:

I have set virtual directory of the WebService to anonymous, why it need
Credentials ?



"Brock Allen" <ballen@NOSPAMdevelop.com>
???????:b8743b137ec8c801d25aa07ac2@msnews.microsof t.com...[color=blue]
> Sounds like IIS is using integrated authentication for that application.
> Your browser supplies the credentials of the logged in user, whereas the
> web service proxy does not. You can either change the code for your web
> service proxy to 1) hard code the credntials, 2) prompt the user and pass
> those credentials, or 3) use the current logged in user's credentials.
> Check out the Credentials property of teh web service proxy. Set it to
> CredentialCache.DefaultCredentials to get the thrid behavior I listed. For
> the first or second, use an instance of the System.Net.NEtworkCredential
> class.
>
> -Brock
> http://staff.develop.com/ballen
>
>[color=green]
>> I have a WebService in localhost, and the set in the web.config is
>>
>> <add key="WebReference.Service"
>> value="http://localhost/HealthService/Service.asmx"/>
>> and the code to refer the WebService is
>> WebReference.Service wsHealth = new WebReference.Service();
>> But when I use code to execute a function in the webservice, like
>> ds =(System.Data.DataSet)wsHealth.GetSchools_Zip(txtZ ip1.Text);
>> it result into an error:
>> The request failed with HTTP status 401: Unauthorized
>> I have type the web service URL into browse, it execute OK, but it
>> can't call in program.
>>
>> How can I do?
>>[/color]
>
>[/color]


Closed Thread