none
SharePoint2013 Hosted App Accessing Custom WCF web Service RRS feed

  • Question

  • Hi,

    I am trying to access custom WCF web service from SP-Hosted Add-in and getting below error, however if we use same peace of code in normal web application I am able to get the data from custom web-service.

    Error: Response Status Text: “Error:Access is Denied.\r\n

    Could you please share the solution, if someone has come across this situation and got the solution?

    I had written below code to call web service and it is written in App.js

    requestUri= "webservice url /parameter ";

     return $.ajax({        

    url: requestUri,        

    type: "GET",        

    data: "",        

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

     ContentType: "application/json; charset=utf-8",         dataType: "json",        

    success: function (data) {             alert(data);         },         error: function (data) {             alert(data);         }     });

    Web.config

    <?xml version="1.0" encoding="UTF-8"?>

    <configuration>

      <configSections>

        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >

          <section name="Namespace.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

        </sectionGroup>

      </configSections>

      <appSettings>

        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />

      </appSettings>

      <system.web>

        <compilation debug="true" targetFramework="4.5" />

        <httpRuntime targetFramework="4.5" />

            <identity impersonate="false" />

            <authentication mode="Windows" />

      </system.web>

      <system.serviceModel>

        <client />

        <!--<bindings>

          <basicHttpBinding>

            <binding name="ExampleBinding" transferMode="Streamed" />

          </basicHttpBinding>

        </bindings>-->

        <services>

          <service name="ServiceName" behaviorConfiguration="ServiceBehavior">

            <endpoint address="" binding="webHttpBinding" contract="serviceController" behaviorConfiguration="httpBehavior">

             

            </endpoint>

          </service>

        </services>

        <behaviors>

          <serviceBehaviors>

            <behavior name="ServiceBehavior">

              <!-- 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>

          <endpointBehaviors>

            <behavior name="httpBehavior">

              <webHttp />

            </behavior>

          </endpointBehaviors>

        </behaviors>

       

        <protocolMapping>

            <add binding="basicHttpsBinding" scheme="https" />

        </protocolMapping>   

        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

     

        <standardEndpoints>

          <webScriptEndpoint>

            <standardEndpoint name="" crossDomainScriptAccessEnabled="true" />

          </webScriptEndpoint>

        </standardEndpoints>   

      </system.serviceModel>

      <system.webServer>

        <httpProtocol>

          <customHeaders>

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

            <add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />

            <add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS" />

            <add name="Access-Control-Max-Age" value="1728000" />

          </customHeaders>

        </httpProtocol>

        <modules runAllManagedModulesForAllRequests="true" />

        <directoryBrowse enabled="true" />

      </system.webServer>

     </configuration>


    • Edited by Sujeet Nisahd Friday, January 13, 2017 12:20 PM Updted with error
    Thursday, January 12, 2017 2:27 PM

Answers

  • Hi All,

    I got the solution, app site was not added in trusted site, got to know when I changed browser for testing , same peace of code working Firefox browser.

    Regards,

    Sujeet

    • Marked as answer by Sujeet Nisahd Friday, January 13, 2017 12:28 PM
    Friday, January 13, 2017 12:24 PM

All replies

  • Hi,

     

    Could you provide the error message when call the service from SharePoint app?

     

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, January 13, 2017 3:18 AM
  • Hi All,

    I got the solution, app site was not added in trusted site, got to know when I changed browser for testing , same peace of code working Firefox browser.

    Regards,

    Sujeet

    • Marked as answer by Sujeet Nisahd Friday, January 13, 2017 12:28 PM
    Friday, January 13, 2017 12:24 PM
  • Hi Lee,

    I got the solution and also updated the error in the questions.

    Thanks!!

    Regards,

    Sujeet

    Friday, January 13, 2017 12:26 PM