views:

305

answers:

1

I'm calling a SharePoint Web Service (Webs.asmx) with JQuery to get a list of all subsites:

$(document).ready(function() {
        var hrefParts = window.location.href.split('/');
        var wsURL = "";
        for (i = 0; i < (hrefParts.length - 2); i++) {
            if (i > 0)
                wsURL += "/";
            wsURL += hrefParts[i];
        }
        wsURL += "/_vti_bin/Webs.asmx";
        var soapEnv =
            "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'&gt; \
                <soapenv:Body> \
                    <GetAllSubWebCollection xmlns='http://schemas.microsoft.com/sharepoint/soap/'&gt; \
                    </GetAllSubWebCollection > \
                </soapenv:Body> \
            </soapenv:Envelope>";

        $.ajax({
            url: wsURL,     
            beforeSend: function  (xhr) {  
 xhr.setRequestHeader("SOAPAction",  "http://schemas.microsoft.com/sharepoint/soap/GetAllSubWebCollection");
},
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            error:function(xhr,err){ 
    alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status); 
    alert("responseText: "+xhr.responseText); 
},
            contentType: "text/xml; charset=\"utf-8\""
        });

    });

    function processResult(xData, status) {
        ...
    }

However, I always get a login problem due to the beforeSend call. If I comment it out, I get an "Access Denied" error page from SharePoint. I have "Full Control" access to the site and all subsites. Calling a different web service (e.g. calling GetListCollection from lists.asmx) is successful.

What could be the problem here?

+1  A: 

This operation requires Site Collection Administrator access, even Full Control is not enough.

You will probably need to iterate thru GetWebCollection instead, or create a proxy page that runs with elevated privileges and returns the webservice response.

F.Aquino
Thanks a lot, that helped me!
Modery