473,324 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 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 64996
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 - Unauthorized: Logon failed due to server...
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 404, like this example: <customErrors...
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 2003, Windows XP Pro and .NET 1.1. I created a...
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 contains around 5000 records (no paging is there)....
0
by: Shree | last post by:
While invoking the web service from client, I am setting the credentitals using the following code... ReportingService.Credentials = System.Net.CredentialCache.DefaultCredentials; But in...
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? code======================== using System; using System.Drawing;...
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 corresponds to a image in the protected directory. I...
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 provided by microsoft with windows authentication....
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 DataSources_ValidURL() As Boolean Dim...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.