473,667 Members | 2,749 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="WebReferen ce.Service"
value="http://localhost/HealthService/Service.asmx"/>
and the code to refer the WebService is
WebReference.Se rvice wsHealth = new WebReference.Se rvice();

But when I use code to execute a function in the webservice, like
ds =(System.Data.D ataSet)wsHealth .GetSchools_Zip (txtZip1.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 65037
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 .DefaultCredent ials
to get the thrid behavior I listed. For the first or second, use an instance
of the System.Net.NEtw orkCredential class.

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

I have a WebService in localhost, and the set in the web.config is

<add key="WebReferen ce.Service"
value="http://localhost/HealthService/Service.asmx"/>
and the code to refer the WebService is
WebReference.Se rvice wsHealth = new WebReference.Se rvice();
But when I use code to execute a function in the webservice, like
ds =(System.Data.D ataSet)wsHealth .GetSchools_Zip (txtZip1.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****@NOSPAMd evelop.com>
???????:b8***** *************** ****@msnews.mic rosoft.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 .DefaultCredent ials to get the thrid behavior I listed. For
the first or second, use an instance of the System.Net.NEtw orkCredential
class.

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

I have a WebService in localhost, and the set in the web.config is

<add key="WebReferen ce.Service"
value="http://localhost/HealthService/Service.asmx"/>
and the code to refer the WebService is
WebReference.Se rvice wsHealth = new WebReference.Se rvice();
But when I use code to execute a function in the webservice, like
ds =(System.Data.D ataSet)wsHealth .GetSchools_Zip (txtZip1.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 configuration what could be wrong ? -- ihookdb Get your data mobile http://www.ihookdb.com
0
1490
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 mode="On"> <error statusCode="404" redirect="http://localhost/ErrorPages/Error404.aspx"/> </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
9472
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 Windows form client. While debugging I get the following error : Unhandled Exception: System.Net.WebException: The request failed with HTTP status 401: Access Denied. in the following line:
0
1792
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). When my page loads, it takes a bit long time to show all the records and show all the records properly. Up till now everything is fine, but when I clicked any operation on same page (which raise some post back event) then the IE ask me for user...
0
2188
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 debugger when I check the properties - 'domain', 'user name' and 'password' set in the ReportingService.Credentials; they are blank!!!
0
1554
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; using System.IO; using System.Web;
1
2757
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 started with this function: $url = "http://website.com/protected/images/image1.jpg"; url_exists($url);
2
3950
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. its working fine in local box. i have uploaded the same to my dev server, i am trying to access same, i am getting this error "The request failed with HTTP status 401: Unauthorized." i have googled for the root cause, i have included...
0
1374
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 TestClient As New WebClient() TestClient.BaseAddress = DataSources_FilePath Try TestClient.DownloadString(DataSources_FilePath) Catch ex As WebException If ex.Status = 401 Then ...
0
8458
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8366
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8790
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8565
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8650
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5677
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4202
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1779
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.