SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been trying since a few days to call a custom made WCF service from a SharePoint Hosted App. I have read all over the information available on forums and I couldn't find a working solution.

When I call my custom WCF service from a test console app, it works perfectly. Although, when I call it withing a SharePoint Hosted App, I get a "403 Forbidden" Error. I read it has to do with the fact that the AppWeb and the HostWeb are in a different domain.

So I tried the "cross-domain" JS Library, but I had no luck to get this working.

I might be doing something wrong, maybe some of you can help...

Here is the code I used in my ap to call the Service:

var hostweburl;
var appweburl;

$(document).ready(function () {
    hostweburl = decodeURIComponent(getParameterByName('SPHostUrl'));
    appweburl = decodeURIComponent(getParameterByName('SPAppWebUrl'))

    var scriptbase = hostweburl + "/_layouts/15/";
    $.getScript(scriptbase + "SP.RequestExecutor.js", CallService);

function CallService()
var exec;
exec = new SP.RequestExecutor(appweburl);
        url: appweburl + "/_vti_bin/CSN.DataService/DataService.svc/GetData?query=QueryHere",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (msg) {
        error: function (data, errorCode, errorMessage) { alert('Error: ' + errorMessage); }

Even with the Cross-Domain Library, I still get a 403 Forbidden error.

I have also tried to add read rights in my app to the site collection level.

I have edited the AppManifest.xml to add an app principal (which I found on MSDN

    <Internal AllowedRemoteHostUrl="~remoteAppUrl" />

All of that didn't work so far. Any help will be welcomed.

share|improve this question
Anybody got an idea? – Pascal Jul 30 '13 at 18:21
up vote 1 down vote accepted

I have found a work around.

I deployed my custom WCF to IIS instead of deploying it into SharePoint (ISAPI). I had to make the WCF service public (to be able to call it cross-domain) by adding this code into the WCF's web.config:

            <add name="Access-Control-Allow-Origin" value="*" />

I then deployed the WCF to IIS and from there I have been able to call if from a standard Jquery Ajax Call:

$(document).ready(function () {

        type: "GET",
        url: "",
        dataType: 'json',
        processdata: true,
        success: function (msg) {
            var JSONmsg = JSON.stringify(msg);

            var Response = document.getElementById('ServiceResponse');
            Response.innerText = JSONmsg;

        error: function (data, errorCode, errorMessage) {
            alert('Error: ' + errorMessage);

Hope this helps.

share|improve this answer
Can we write a code to read audit logs in wcf service for SharePoint online? So I want to pass a url of page that user visited to a wcf service and wcf service then gets audit logs based on passed url. Is it possible? – mit Feb 18 '14 at 11:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.