none
How to consume the WCF rest service from web part class file RRS feed

  • Question

  • Hi,

    I have a requirement where I need to consume a RESTful web service from the web part class file and the .svc is hosted in a different server and there is a S2S connection established between the sharepoint server and where the service hosted server.

    I tried to consume the service by adding the service reference and copied the service.model from the app.config added in the sharepoint web.config file and getting the below error:

    The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were

    Checked that the WCF non-HTTP activation components is installed on the sharepoint server

    Any help on this is much appreciated.



    Rayudu

    Friday, November 28, 2014 2:22 PM

All replies

  • hi

    Did you try, to call directly your service in a browser?

    if you still get an error on browser please paste it here.


    Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer

    Friday, November 28, 2014 7:49 PM
  • Hi Nikhil,
    I am able to browser the service and there is no error, can able to see the methods in it.


    Rayudu

    Saturday, November 29, 2014 6:30 PM
  • Hi,

    try enabling servicemetada in behaviour section

    <serviceMetadata httpGetEnabled="True"/>

    for reference

    <configuration>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="SimpleServiceBehavior">
              <serviceMetadata httpGetEnabled="True" policyVersion="Policy12" />
              <serviceDebug includeExceptionDetailInFaults="False" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>


    Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer

    Saturday, November 29, 2014 6:41 PM
  • The servicemetadata is already enabled in the behaviour section, still facing the same issue.

    Rayudu

    Tuesday, December 2, 2014 7:16 AM
  • Hello All,

    After doing R&D for a while found that when the service is hosted on a different server, then we have to create the web method in such a way that it returns in a JSONP format. This will not create any issue when we try to access the service from the Sharepoint.


    Rayudu

    Tuesday, January 20, 2015 6:13 PM