none
How to check if a web-service using the soap or rest? RRS feed

  • Question

  • I have a WCF web service which works in both soap and rest services. my web service URL is something like this: http://localhost/TestWS.svc the client can use this address: http://localhost/TestWS.svc/rest to access the rest with json and this address: http://localhost/TestWS.svc/soap to access the soap with XML.

    i consume my web service with desktop application. i just add the URL(without soap and rest at the end of it) and then call the functions. but which standard(soap or rest) used when i call the functions in consumer?

    Thursday, June 25, 2015 12:48 PM

Answers

  • hi Bouki,
       According to this case, you need to specify the different endpoint for enable REST and SOAP in the same config file like below :

    <?xml version="1.0"?>
    <configuration>
    <system.web>
    <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
    <behaviors>
    <serviceBehaviors>
    <behavior name ="servicebehavior">
    <serviceMetadata httpGetEnabled="true"/>
    <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
    <behavior name="restbehavior">
    <webHttp/>
    </behavior>
    </endpointBehaviors>
    </behaviors>
    <services>
    <service name ="MultipleBindingWCF.Service1"
    behaviorConfiguration ="servicebehavior" >
    <endpoint name ="SOAPEndPoint"
    contract ="MultipleBindingWCF.IService1"
    binding ="basicHttpBinding"
    address ="soap" />
     
    <endpoint name ="RESTEndPoint"
    contract ="MultipleBindingWCF.IService2"
    binding ="webHttpBinding"
    address ="rest"
    behaviorConfiguration ="restbehavior"/>
     
    <endpoint contract="IMetadataExchange"
    binding="mexHttpBinding"
    address="mex" />
    </service>
    </services>
    </system.serviceModel>
    <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
    </configuration>
    

    for more information, refer the following links :

    1.Click here to refer about How to enable REST and SOAP both on the same WCF Service

    2.Click here to refer about Expose WCF 4.0 Service as SOAP and REST.

    • Marked as answer by Bouki Saturday, July 11, 2015 6:10 AM
    Thursday, July 9, 2015 7:34 AM

All replies

  • Hi Bouki,

    >> i just add the URL(without soap and rest at the end of it) and then call the functions.

    Are you using the "add services reference" to consume the WCF Service? If so the soap service will be used when you call the function in the consumer. If you want to call the rest service, you may need to use HttpWebRequest/HttpClient/Jquery to help you. For more information about how to consume the WCF Rest Service, please try to refer to the following articles:
    #Call Restful Service using HttpWebRequest:
    http://fromjami.wordpress.com/2013/05/26/call-restful-service-using-httpwebrequest-and-post-data/ .
    #Create and consume WCF Restful Service using an HttpClient:
    http://chsakell.com/2013/07/12/create-and-consume-wcf-restful-service-using-an-httpclient/ .
    #Consume RESTful service using jQuery in 2 simple steps:
    http://www.topwcftutorials.net/2013/10/consume-rest-service-using-jquery.html .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, June 26, 2015 5:16 AM
    Moderator
  • thank you dear Amy.

    you exactly right. I'm using "add services reference" to consume the WCF Service. so if i remove the soap the endpoint? now what?

    i mean my web service no longer support the soap service. but when i added services reference, i consume it just like before. it means now I'm using rest? or even in this case some how i use the soap service!!

    thank you.

    Friday, June 26, 2015 7:12 AM
  • hi Bouki,
       According to this case, you need to specify the different endpoint for enable REST and SOAP in the same config file like below :

    <?xml version="1.0"?>
    <configuration>
    <system.web>
    <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
    <behaviors>
    <serviceBehaviors>
    <behavior name ="servicebehavior">
    <serviceMetadata httpGetEnabled="true"/>
    <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
    <behavior name="restbehavior">
    <webHttp/>
    </behavior>
    </endpointBehaviors>
    </behaviors>
    <services>
    <service name ="MultipleBindingWCF.Service1"
    behaviorConfiguration ="servicebehavior" >
    <endpoint name ="SOAPEndPoint"
    contract ="MultipleBindingWCF.IService1"
    binding ="basicHttpBinding"
    address ="soap" />
     
    <endpoint name ="RESTEndPoint"
    contract ="MultipleBindingWCF.IService2"
    binding ="webHttpBinding"
    address ="rest"
    behaviorConfiguration ="restbehavior"/>
     
    <endpoint contract="IMetadataExchange"
    binding="mexHttpBinding"
    address="mex" />
    </service>
    </services>
    </system.serviceModel>
    <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
    </configuration>
    

    for more information, refer the following links :

    1.Click here to refer about How to enable REST and SOAP both on the same WCF Service

    2.Click here to refer about Expose WCF 4.0 Service as SOAP and REST.

    • Marked as answer by Bouki Saturday, July 11, 2015 6:10 AM
    Thursday, July 9, 2015 7:34 AM