2

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\""
    });
2

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.

  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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