locked
Webs Webservices problem : The request failed with HTTP status 401: Unauthorized RRS feed

  • Question

  • I am trying to run this code to get the web collection details. I am running this code in debug mode in Visual Studio 2005. I am running this code on sharepoint.acme.com, the same machine on which MOSS 2007 is installed.

            Webs websService = new Webs();
            System.Net.SystemNetworkCredential credentials =
            websService.Credentials = System.Net.CredentialCache.DefaultCredentials;
            websService.Url = "http://sharepoint.acme.com/_vti_bin/Webs.asmx";

            System.Xml.XmlNode myNode = websService.GetAllSubWebCollection();

    I get this error. "The request failed with HTTP status 401: Unauthorized" in the last line while debug mode running. Earlier it used to work fine, but today I see this problem. Both acme\administrator and sharepoint\administrator can log into SharePoint. I tried running this code by logging in to my win2k3 desktop as acme\administrator once and launching Visual Studio 2005 and sharepoint\administrator another time. Both time it I got the same error.

    Could someone please help me in resolving this error?
    Friday, February 20, 2009 12:59 PM

Answers

  • 1º Verify if you Crawl is working....

    If yes, verify if this article help
    You receive error 401.1 when you browse a Web site that uses Integrated Authentication and is hosted on IIS 5.1 or IIS 6
    http://support.microsoft.com/?scid=kb;en-us;896861&x=14&y=17

    I Have some errors acessing web services and this article help....
    André Lage Microsoft SharePoint and CRM Consultant http://aaclage.blogspot.com
    • Proposed as answer by nims2 Thursday, March 26, 2009 11:01 AM
    • Marked as answer by Michael Washam - MSFT Thursday, March 26, 2009 12:53 PM
    Tuesday, March 24, 2009 6:08 PM

All replies

  • Verify in IIS "Sharepoint Site"->Properties->"Directory Security"->"Auhentication access mode-Options"

    Verify if you have "Enable anonymous access" Checked, if you have you will have to uncheck, web services dont acces anonymous access.

    Hope this help

    André Lage Microsoft SharePoint and CRM Consultant http://aaclage.blogspot.com
    Friday, February 20, 2009 2:03 PM
  • It is not checked. It is unchecked by default. Instead "Integrated Windows Authentication" is checked. Please note that I face this problem only with Web.asmx. It works fine if I try to access other web services such as http://sharepoint.acme.com/_vti_bin/UserGroup.asmx

    Please help
    Friday, February 20, 2009 2:18 PM
  • Did you compare the authentication methods of the webs.asmx file with other files which you can access?
    Friday, February 20, 2009 2:48 PM
  • I did some bit of debugging myself with WireShark. Code for UserGroup seems to be doing a proper NTLM authentication. However, code for Webs is not even sending a valid HTTP response to respond to the NTLM challenge. The response starts directly with the <?xml version="1.0" encoding="utf-8"?><soap:Envelope ... with no POST line at all. There is no "Authorization" header also in this faulty response.
    Friday, February 20, 2009 2:56 PM
  • Well, what reports you the 401 error? If you are getting an XML as a response from the Webs, then authentication passed and something else reports 401. Does the XML contain the error? (in which case your web service is most likely trying to access something else and gets 401 and then passes the buck). Just guessing here...
    Friday, February 20, 2009 4:42 PM
  • The error does not come as an XML. It is an HTML page that comes as response with the 401 Unauthorized error.
    Saturday, February 21, 2009 6:25 AM
  • Did you already solve this problem? I am receiving the same problem when calling the webservice from a webcontrol. I receive a 401 error:

    The request failed with HTTP status 401: Unauthorized. at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at Avensus.Nintex.WebControls.profiles.UserProfileService.GetUserProfileByName(String AccountName) at WebControls.DefaultApprover.CreateChildControlsElevated()

    I tried to put authentication in the code:

            protected override void CreateChildControls() { 
                SPSecurity.CodeToRunElevated ElevatedCode = new SPSecurity.CodeToRunElevated(CreateChildControlsElevated); 
                SPSecurity.RunWithElevatedPrivileges(CreateChildControlsElevated); 
      
            } 
     
            protected void CreateChildControlsElevated() { 
                try { 
                    if (!Page.IsPostBack) { 
                        profiles.UserProfileService p = new profiles.UserProfileService(); 
      
                        p.PreAuthenticate = true
                        p.Credentials = System.Net.CredentialCache.DefaultCredentials; 
                        p.UseDefaultCredentials = true
      
                        profiles.PropertyData[] pd; 
                        try { 
                            ppd = p.GetUserProfileByName(Context.User.Identity.Name); 
                        } 
                        catch (Exception e8) { 
                           lctl.Text += e7.Message + e7.StackTrace; 
                           lctl.Text += "<br>Context.User.Identity.Name = "; 
                           lctl.Text += Context.User.Identity.Name; 
                           lctl.Text += "<br>System.Net.CredentialCache.DefaultCredentials = "; 
                           lctl.Text += System.Net.CredentialCache.DefaultCredentials.ToString(); 
                           return; 
                        } 
                } 
            } 

    When I look into the IIS logfile, I see the call is not sending any username and password to the service (because it is not authenticated):

    2009-03-24 13:09:09 W3SVC666786632 127.0.0.1 POST /wijzigingsverzoeken/_vti_bin/userprofileservice.asmx - 80 - 127.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+2.0.50727.3053) 401 2 2148074254
    2009-03-24 13:09:09 W3SVC666786632 127.0.0.1 POST /wijzigingsverzoeken/_vti_bin/userprofileservice.asmx - 80 - 127.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+2.0.50727.3053) 401 1 0
    2009-03-24 13:09:09 W3SVC666786632 127.0.0.1 POST /wijzigingsverzoeken/_vti_bin/userprofileservice.asmx - 80 - 127.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+2.0.50727.3053) 401 1 2148074252
    2009-03-24 13:09:09 W3SVC666786632 127.0.0.1 POST /wijzigingsverzoeken/_vti_bin/userprofileservice.asmx - 80 - 127.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+2.0.50727.3053) 401 2 2148074254
    2009-03-24 13:09:09 W3SVC666786632 127.0.0.1 POST /wijzigingsverzoeken/_vti_bin/userprofileservice.asmx - 80 - 127.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+2.0.50727.3053) 401 1 0
    2009-03-24 13:09:09 W3SVC666786632 127.0.0.1 POST /wijzigingsverzoeken/_vti_bin/userprofileservice.asmx - 80 - 127.0.0.1 Mozilla/4.0+(compatible;+MSIE+6.0;+MS+Web+Services+Client+Protocol+2.0.50727.3053) 401 1 2148074252


    Any clues what is going on here?
    Tuesday, March 24, 2009 2:36 PM
  • 1º Verify if you Crawl is working....

    If yes, verify if this article help
    You receive error 401.1 when you browse a Web site that uses Integrated Authentication and is hosted on IIS 5.1 or IIS 6
    http://support.microsoft.com/?scid=kb;en-us;896861&x=14&y=17

    I Have some errors acessing web services and this article help....
    André Lage Microsoft SharePoint and CRM Consultant http://aaclage.blogspot.com
    • Proposed as answer by nims2 Thursday, March 26, 2009 11:01 AM
    • Marked as answer by Michael Washam - MSFT Thursday, March 26, 2009 12:53 PM
    Tuesday, March 24, 2009 6:08 PM
  • Yes indeed that was my problem. I used my hostfile to make the site accesible and the loopback adapter was blocking the connection.
    Thursday, March 26, 2009 11:01 AM
  • I have a very similar issue, but it's true both on the local server as well as from remote clients.  Are there any other solutions to this problem?  I have already tried the DisableLoopbackCheck registry key to no effect.
    ben
    Wednesday, January 27, 2010 11:17 PM
  • I've finally solved the same issue. 401 returned when trying to update using datasheet view or connecting with Excel.

    The reason was misconfigured httpModules section in web.config. Simply removing tag: <add name="ScriptModule" ... solved my problem.
    So, double check sections httpModules and httpHandlers. You can create a fresh sp web app and check wheather the problem lasts and sync the two sections.

    Good luck!
    Géza

    Wednesday, September 29, 2010 12:44 PM