zoukankan      html  css  js  c++  java
  • Web Service Error: “The request failed with HTTP status 401: Unauthorized.”ZT

    Web Service Error: “The request failed with HTTP status 401: Unauthorized.”

    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();

    HabibH.
    6:46 PM 5/25/2005.

    Published Wednesday, May 25, 2005 8:46 PM by habibh
    Filed under: Debugging
  • 相关阅读:
    struts2 <s:iterator> 遍历方法
    JSP 基础之 JSTL <c:forEach>用法
    struts2 中 Session的使用简介
    Struts2 工作流程
    Aandroid Error之 新导入工程报Unable to resolve target 'android-18'和R cannot be resolved
    纯Html+Ajax和JSP两者对比的个人理解
    移动互联网App兼容性测试
    【转】【Mac】invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library
    【转】Mac使用apt-get
    有趣网址之家 – 收藏全球最有趣的网站
  • 原文地址:https://www.cnblogs.com/liangqihui/p/1113031.html
Copyright © 2011-2022 走看看