Hi,
I'm trying to call UserProfileService.asmx service from SharePoint Hosted App.
I've added myserver host name to the AppManifest remote endpoints.
<RemoteEndpoints><RemoteEndpoint Url="http://myserver/_vti_bin/UserProfileService.asmx" /></RemoteEndpoints>
I've tried in two ways
jQuery.support.cors = true;
.ajax({ crossDomain:true, url: "http://myserver/_vti_bin/UserProfileService.asmx/GetProfileSchemaNames", headers: { "accept": "application/json;odata=verbose" }, success: function (data) { alert("ok"); }, error: function (data, errorCode, errorMessage) { alert("error"); } });
and I'm getting 'Access is denied' error.
I've tried also using SP.WebProxy:
var context = SP.ClientContext.get_current(); var request = new SP.WebRequestInfo(); request.set_url("http://myserver/_vti_bin/UserProfileService.asmx/GetProfileSchemaNames"); request.set_method("GET"); request.set_headers({ "Accept": "application/json;odata=verbose" }); var response = SP.WebProxy.invoke(context, request); context.executeQueryAsync( function () => { alert("respose status code: " + response.get_statusCode().toString() + "; " + response.get_body()); }, function (error) => { alert(error); });
but I'm getting 401 error: “Remote server returned the following error while establishing a connection – ‘Unauthorized’”.
I've also do investigation with SP.RequestExecutor, but I think it is not useful for my problem, I'm not calling app from other server.
How can I overcome that issue?