0

I would like to call an On-Premises WCF Service from an ajax call in a script editor webpart but i've not been able to do so. This is a very simple WCF I'm trying to call from SharePoint Online.

First Issue is that SharePoint Online is https and my WCF service is http so I receibve this error message:

HTTPS security is compromised by http:///TestWCF/Service1.svc/GetData?callback=save&_=1561584213260

I've managed to setup IIS 7 to allow https request and configured my service to receive calls on SSL. But still cannot perform an ajax call. This is my Service and webconfig:

namespace WcfService1
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IService1
    {

        [OperationContract]
        string GetData();
    }
}

This is my implementation:

namespace WcfService1
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
    public class Service1 : IService1
    {
        public string GetData()
        {
            return "Hello World";
        }
    }
}

This is my webconfig:

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

this is my code from the script editor webpart I'm using to try to call the service:

function getSiteDetails(){
    alert("Site Details");

    $.ajax({
        url: 'http://<server>/TestWCF/Service1.svc/GetData',
        type: 'POST',
        async: true,
        jsonp:"callback",
        jsonpCallback: "save",
        contentType: 'application/json',
        processData: false,
        crossDomain: true,
        dataType: 'jsonp',
        succes: function (response) {
            alert("Success");
        },
        error: function (response) {
            alert("failed!");
        }
    });
}

What Do I need to do to successfully be able to call my service from SharePoint Online Environment? thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.