Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm attempting to do a pretty straightforward query to the list.asmx web service and I keep getting a 401 error. I've spent a couple of hours attempting to solve it with no luck.

My jQuery Code:

    $.ajax({
        type: "POST",
        url: "http://devsp2:3050/_vti_bin/lists.asmx/GetList",
        data: '{"listName":"Site Pages"}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        xhrFields: {
            withCredentials: true
        }
    })

Error Details:

When I execute the code on a test page with a simple button click it prompts me to authenticate. However it asks me to authenticate to the servername.company.com and not the headername I passed.

Firebug returns:

{"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""}

Fiddler returns (Raw):

HTTP/1.1 401 Unauthorized Content-Type: text/html; charset=utf-8 Server: Microsoft-IIS/7.5 SPRequestGuid: 9ed17429-0633-4bb8-82dd-fb086b86977f WWW-Authenticate: NTLM X-Powered-By: ASP.NET MicrosoftSharePointTeamServices: 14.0.0.4762 Date: Thu, 03 May 2012 19:43:08 GMT Content-Length: 16 Proxy-Support: Session-Based-Authentication

401 UNAUTHORIZED

soapUI

When I query the same web service using the same credentials with soapUI, it works great.

Attempted Solutions:

  • Registry Edits
    • BackConnectionHostNames
    • DisableLoopbackCheck
  • withCredentials in jQuery

Updated: Successful Solution

Thanks to @Mark D Anderson for pointing me in the right direction. The below code works. Credit to Jan Tielen as well (http://weblogs.asp.net/jan/archive/2009/04/09/calling-the-sharepoint-web-services-with-jquery.aspx)

    var soapEnv =
    "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
        <soapenv:Body> \
            <GetListCollection xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
            </GetListCollection> \
        </soapenv:Body> \
    </soapenv:Envelope>";

    $.ajax({
        url: "http://devsp2:3050/_vti_bin/lists.asmx",
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        contentType: "text/xml; charset=\"utf-8\""
    });
share|improve this question
    
Have you setup an alternate access mapping for devsp2? –  theChrisKent May 3 '12 at 20:27
    
I did not on devsp2:3050 (this is my mysites web application) but I did for devsp2. I changed the public url to sprocks. –  RWL01 May 3 '12 at 20:31
    
Are you able to get there in a browser (The site, not the web service)? –  theChrisKent May 3 '12 at 20:34
    
Yes, I can get to devsp2:3050/_vti_bin/lists.asmx and devsp2:3050/_vti_bin/lists.asmx?op=GetList. However, when I go to devsp2:3050/_vti_bin/lists.asmx?op=GetList it doesn't allow me to test it even though I'm accessing it from the local server. –  RWL01 May 3 '12 at 20:36
    
could be some kind of transparent proxy in play as well, or a proxy that is modifying the auth messages. I see the site is using NTLM –  pigeon May 4 '12 at 1:36

1 Answer 1

up vote 1 down vote accepted

I think that the issue is that you are trying to pass JSON data to a SOAP Web Service, which expects XML. Plus, you're not passing in the SOAP envelope which is required. Take a look at SPServices for examples of how to call the SOAP Web Services.

share|improve this answer
    
This was the issue, thanks for help. I have other SP web services I built that take JSON without any issue so I'm going to compare the two and see what I'm doing differently. –  RWL01 May 8 '12 at 13:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.