473,511 Members | 15,408 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 65021
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
641
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
1474
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
1161
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
9466
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
1781
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
2177
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
1540
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
2751
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
3945
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
1354
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
7138
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7418
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5662
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5063
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
446
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.