I am trying to perform a cross domain request from SharePoint hosted add-in to a wcf service in provider hosted add-in.

I have a hybrid setup as below:

  • SharePoint Office 365 site online, Azure subscription & other required elements in Azure AD
  • A SharePoint hosted Add-in with a custom action and custom page, deployed successfully.
  • A provider hosted Add-in which has a wcf RESTfulservice, deployed and published successfully. I see the correct response when requested through browser.

Scenario: On a button click from a SharePoint hosted Add-in page, I would like to perform a cross domain request to WCF service which is hosted in Provider hosted Add-in. So ideally I am trying to get information from host web & perform some updates. But to start off , there is only one operation contract returning a string.

Please find the sample JavaScript:

try {

   context = new SP.ClientContext(appWebUrl);

   var executor = new SP.RequestExecutor(appWebUrl);

   var localHostUrl = "http://amigosito365.azurewebsites.net/MyHybridService.svc/GetResponse";

   //var localHostUrl = appWebUrl + "/_api/SP.AppContextSite(@target)/web/title?@target='" +

   // hostWebUrl + "'";



      url: encodeURIComponent(localHostUrl),

      //url: localHostUrl,

      method: "GET",

      headers: { "Accept": "application/json; odata=verbose" },

      success: onQuerySucceeded,

      error: onQueryFailed,

      DataType: "jsonp"



Using the above code, If I try to get the web title using the URL: //var localHostUrl = appWebUrl + "/_api/SP.AppContextSite(@target)/web/title?@target='" +

// hostWebUrl + "'";

I get the response json as expected however when I try to communicate with the RESTful service the response is not as excepted. I do not get any specific error and I am able to get in to the success call back function. But the body of data object has a big chunk of html and does not indicate any error.

On the other hand when I access the RESTful service in a web browser, I am seeing the response as expected.

Any help in solving the above issue would be really appreciated.


Using SP.WebRequestInfo() to set the webservice url & execute the request through web proxy fixed the issues.

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.