Quantcast
Channel: Developing Apps for SharePoint 2013 forum
Viewing all articles
Browse latest Browse all 8089

How to call UserProfileService.asmx in a SharePoint Hosted App - cross-domain issue?

$
0
0

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?



Viewing all articles
Browse latest Browse all 8089

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>