Web Service Error: “The request failed with HTTP status 401: Unauthorized.”
来源:互联网 发布:三菱plcq系列怎么编程 编辑:程序博客网 时间:2024/06/05 12:46
I’ve come across a number of developers who have run into this issue when trying to call a web service in Visual Studio 2005 Beta 2. The symptom of the problem is that when trying to call a web service that is running on the "ASP.NET Development Server" from another application, the web service throws a WebException with the message: “The request failed with HTTP status 401: Unauthorized.”
First and foremost, this issue is not related to debugging. If you run the application outside of Visual Studio, you’ll see the same result. Also noteworthy to mention is that when you run the web service by itself, everything works fine. It’s only when you call the web service from another application that it fails.
Why do I get this error?
The reason for this error is that by default, a web service project in Visual Studio 2005 Beta 2 required NTLM authentication. When you call the web service from another application, the application tries to call into the web service with anonymous access and fails. But, when you call the web service from the web service test page in Internet Explorer, your credentials are passed from IE to the web service which means that the call succeeds.
How do I fix this error?
There are two ways to fix this error.
1. Disable NTLM Authentication in Project Properties
If your web service is not intended to require authentication, the easiest way to fix this error is to turn off NTML authentication in a web service project. To do this, right click on the web service project and select “Property Pages”. On the “Start Options” page, uncheck “NTLM Authentication”. NOTE: disabling this option has security implications if you are running the web service in a Terminal Server environment. If the web service is on your local machine and it’s not being used in a Terminal Server environment, then you should be fine.
2. Pass User's Credentials from Calling Application to Web Service
If your web service is intended to require authentication and not anonymous access, then pass the credentials of the user from the application to the web service. Here is an example:
Samples.TimeWebService ws = new Samples.TimeWebService();
ws.Credentials = System.Net.CredentialCache.DefaultCredentials;
string currentTime = ws.GetCurrentTime();
- Web Service Error: “The request failed with HTTP status 401: Unauthorized.”
- Web Service Error: “The request failed with HTTP status 401: Unauthorized.”
- the request failed with http status 401:unauthorized
- The request failed with HTTP status 401: Unauthorized
- Web service request SetParameters to Report Server http://host/reportserver failed. Error: 请求因 HTTP 状态 401 失败: Unauthorized
- Web service: The HTTP request is unauthorized with client authentication scheme 'Anonymous'.....
- Web Service 之 Exception: "The HTTP request is unauthorized with client authentication scheme......"
- The request failed with HTTP status 401:Access Denied
- The request failed with HTTP status 401:Access Denied
- The request failed with HTTP status 401: Access Denied
- Web Service 使用时出现 HTTP Status 401: Unauthorized
- The request failed with HTTP status 417: Expectation failed.
- 调用webservice时报错The request failed with HTTP status 401: Access Denied. 的解决方案。
- LoadRunner: Error HTTP Status Code 401 Unauthorized during script replay
- The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the serv
- Failed to load webpage with error: The request timed out.
- Failed to load resource: the server responded with a status of 400 (Bad Request)
- Failed to load resource: the server responded with a status of 400 (Bad Request)
- 五种提高 SQL 性能的方法
- Frameset 使用详解
- 查找两个表中数据库不同的记录
- ubuntu8.10下播放rmvb文件
- 55个最常被问到的面试问题
- Web Service Error: “The request failed with HTTP status 401: Unauthorized.”
- 0x0d 0x0a
- 中国数字家庭服务联盟正式成立
- myeclipse中显示js的中文是乱码
- 当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'WLog' 中的标识列插入显式值。
- 培训方案(*_*)Y
- 迈向程序员的第一步
- 在处理向该请求提供服务所需的配置文件时出错。请检查下面的特定错误详细信息并适当地修改配置文件。
- robots.txt作用&使用方法