SPServices across domains

Apr 20, 2014 at 8:42 PM
Edited Apr 20, 2014 at 8:50 PM
I have an application in 1 site collection and I'm trying to get it to return operation: "GetUserCollectionFromSite" from a different collection.

The different collections are in the same web application, the account I use in the collection where the application is running is the same account used in the site I am trying to reach. They are both collection admins.

I'm setting my webURL using the defaults object:
        //SET DEFAULT APPLICATION WEBURL FOR SPSERVICES
        $scope.setWebURL = function (portal) {
            console.log(portal);
            var webURL = portal.webURL;
            $().SPServices.defaults.webURL = webURL;
        }
This is the result I get:
Request URL:https://target.ca/_vti_bin/usergroup.asmx
Request Method:OPTIONS
Status Code:401 Unauthorized
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:accept, content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:target.ca
Origin:https://origin.ca
Referer:https://origin.ca/md/SitePages/Home.aspx
User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36
Response Headersview source
Connection:Keep-Alive
Content-Length:16
Content-Type:text/html; charset=utf-8
Date:Sun, 20 Apr 2014 20:37:03 GMT
MicrosoftSharePointTeamServices:14.0.0.6106
Server:Microsoft-IIS/7.5
SPRequestGuid:6337ec3d-f95f-4045-913e-feaef69e9064
WWW-Authenticate:NTLM
WWW-Authenticate:Basic realm="serviceottawa.ottawa.ca"
X-Powered-By:ASP.NET
Errors in console:
OPTIONS https://spweb2.ca/_vti_bin/usergroup.asmx 401 (Unauthorized)

XMLHttpRequest cannot load https://target.ca/_vti_bin/usergroup.asmx. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://origine.ca' is therefore not allowed access. jquery.js:8706
Apr 21, 2014 at 11:51 AM
I ran into a similar problem once. There are a handful of web services available to return user information from a site. I finally achieved success across domains using the operation "GetAllUserCollectionFromWeb" and setting CORS support to true such as...
$.support.cors = true;                     //Enable Cross-Origin Resource Sharing
$().SPServices({
    operation: "GetAllUserCollectionFromWeb",
    async: false,
    webURL: strSiteURL,
    completefunc: function(xData, Status) {
        $(xData.responseXML).SPFilterNode("User").each(function() {
            //Do stuff here
        });
    }
});
I am able to get user lists from all of my site collections across all of my domains using this method.

Geoff
Apr 21, 2014 at 6:06 PM
I've tried this but it didn't work.

I should mention that my errors change from:
OPTIONS https://spweb2.ca/_vti_bin/usergroup.asmx 401 (Unauthorized)

XMLHttpRequest cannot load https://target.ca/_vti_bin/usergroup.asmx. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://origine.ca' is therefore not allowed access. jquery.js:8706
To
OPTIONS https://target.ca/_layouts/error.aspx?ErrorText=Request%20format%20is%20unrecognized%2E 405 (Method Not Allowed)
XML:
Request URL:https://tpfm.ottawa.ca/_layouts/error.aspx?ErrorText=Request%20format%20is%20unrecognized%2E
Request Method:OPTIONS
Status Code:405 Method Not Allowed
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:accept, content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:tpfm.ottawa.ca
Origin:https://hosted.compulite.ca
Referer:https://hosted.compulite.ca/md/SitePages/Home.aspx
User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36
Query String Parametersview sourceview URL encoded
ErrorText:Request format is unrecognized.
Response Headersview source
Allow:GET, HEAD, OPTIONS, TRACE
Connection:Keep-Alive
Content-Length:0
Date:Mon, 21 Apr 2014 18:04:52 GMT
MicrosoftSharePointTeamServices:14.0.0.6106
Server:Microsoft-IIS/7.0
SPRequestGuid:8114792b-5434-4d9f-a745-c7a9f867774d
X-Powered-By:ASP.NET
X-SharePointHealthScore:0