472,328 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

The request failed with HTTP status 401: Unauthorized

ad
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?

Feb 17 '06 #1
2 64820
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

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?

Feb 17 '06 #2
ad
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" <ba****@NOSPAMdevelop.com>
???????:b8************************@msnews.microsof t.com...
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

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?


Feb 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Lloyd Dupont | last post by:
I create a sample test project and it while it works well with IE, when I try to connect to it with Mozilla I get the error page for HTTP 401.2 -...
0
by: Daniel Kopp | last post by:
Hi! I tried to implement custom error pages using the <customErrors> directive in a web.config file. It worked fine for "simple" errors like HTTP...
2
by: Sachin | last post by:
Scenario: Machine A: ASP.NET Web UI IIS 6.0 Windows Server 2003 Impersonation Account: domain\Acct1 Machine B: ASP.NET Web Service IIS 6.0
1
by: Rachel | last post by:
I have created a simple web service in VC# that adds two numbers. It returns an integer value to the client once invoked. I used Visual Studio .NET...
0
by: muzafferhusain | last post by:
Hi, Please help me out in one problem with ASP.NET page. The scenario is something like that, my page contains one data grid and that grid...
0
by: Shree | last post by:
While invoking the web service from client, I am setting the credentitals using the following code... ReportingService.Credentials =...
0
by: tualbuquerque | last post by:
Hi, I am using XP PRo, .NET 2003 and IIS. I am getting a 401 and I 100% my authentication should be fine. Any thoughts? ...
1
by: chromis | last post by:
Hi there, I have a directory with windows authentication on it and i want my script to check whether an image file exists at a URL which...
2
by: vbsramesh | last post by:
Hi, i am ramesh working on MSPS 2007.i have created a webapplication(framework 2.0) with windows authentication. i am consuming MSPS web services...
0
by: alex21 | last post by:
I'm trying to detect the http status number such as (401 Unauthorized) from a 'WebException' when a WebClient in my code fails. Public Function...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.