none
HOw to provide RESTFull end point to my actuall WCP service RRS feed

  • Question

  • Dear all,

    I just build a set of WCF service hosted on an Azure web site which has been initially define to be easily intergrated under VS . net as add reference. So the actuall protocol is normal SOAP.

    IN order to allows more flexibility for exemple being able to use our service through a mobile device I guess SOAP will bring some limitation correct ?

    Is there an easy way to convert my existing WCF working method to be accessible through REST full end point and return as well Json syntax.

    Do I need to provide defferent endpoint for SOAP, JSON, REST FULL ressource

    Not so familiar with this, thanks for you support

    regards

    Saturday, May 17, 2014 8:35 AM

All replies

  • Hi,

    In my mind I think maybe you can create two endpoints, one is for the soap service, then the other is for the restful service. Then if you want to use the soap service, you can call the soap endpoint; Then you want to use your service through a mobile device, then you can use the wcf restful service with the json.

    Then the web.config file will look like below:

    <system.serviceModel>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="false" />
         <services>
          <service behaviorConfiguration="WebServiceBehavior" name="MyService.Service">
            <endpoint address="" behaviorConfiguration="jsonBehavior" binding="webHttpBinding"
              bindingConfiguration="webHttpBindingWithJsonP" contract="MyService.IService" />
            <endpoint address="soap" binding="basicHttpBinding" contract="MyService.IService" />
          </service>
        </services>
    
        <behaviors>
          <endpointBehaviors>
            <behavior name="jsonBehavior">
              <webHttp helpEnabled="true"/>
            </behavior>
          </endpointBehaviors>
    
          <serviceBehaviors>
            <behavior name="WebServiceBehavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
    
        <bindings>
          <webHttpBinding>
            <binding name="webHttpBindingWithJsonP"
                     crossDomainScriptAccessEnabled="true" />
          </webHttpBinding>
        </bindings>
      </system.serviceModel>

    For more information, please try to refer to:
    #Consume WCF Service with JSON and SOAP endpoints:
    http://www.codeproject.com/Articles/425702/Consume-WCF-Service-with-JSONP-and-SOAP-endpoints.
    #Exposing WCF services with SOAP and REST endpoints:
    http://jaysongo.wordpress.com/2013/01/02/exposing-wcf-services-with-soap-and-rest-endpoints/ .

    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.

    Monday, May 19, 2014 5:33 AM
    Moderator
  • Does it measn I have to create to service as well for being RESFULL or I can keep my exisiting WCF soap service and all magic happen in config file?

    I have read somewhere that a service to ne RESTFULL need to implement the WebMethod attribute which I do not have for now..

    thanks for clarification

    regards

    Monday, May 19, 2014 12:35 PM
  • Hi,

    I am sorry for the late reply, then in my mind you have to implement the WebMethod attribute for the WCF Rest Service.

    The following articles will tell you how to create a WCF Rest Service, please try to check it:
    #A Beginner's Tutorial on Creating WCF REST Services:
    http://www.codeproject.com/Articles/571813/A-Beginners-Tutorial-on-Creating-WCF-REST-Services .

    #Create RESTful WCF Service: Step By Step Guide:
    http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide .

    #5 simple steps to create your first RESTful service:
    http://www.topwcftutorials.net/2013/09/simple-steps-for-restful-service.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.

    Tuesday, June 3, 2014 8:17 AM
    Moderator
  • Thanks for your reply.

    Implementation is clear but now I have a big issue.

    The following is one declaration method  I used in my WCF soap service :

    [OperationContract]
    		[FaultContract(typeof(CMSMError))]
            bool GetStoreStatus(SyncParam SyncParam);

    If I need to implement the RESTFULL attribute how can I pass the SyncParam which is a custome define Type define as below :

    [DataContract]
    	public class SyncParam
    	{		
    		[DataMember]
    		public System.Guid SyncKey { get; set; }
    		[DataMember]
    		public System.DateTime StartDate { get; set; }
    		[DataMember]
    		public bool IsFullSync { get; set; }
    	}

    Any idea how should I do ?

    regards

    Tuesday, June 3, 2014 7:49 PM
  • Hi,

    You can use the json data to help you, for more information, please try to refer to:

     [OperationContract]
     [WebInvoke(Method="POST", UriTemplate="GetStoreStatus", ResponseFormat=WebMessageFormat.Json,RequestFormat=WebMessageFormat.Json)]
     bool GetStoreStatus(SyncParam SyncParam);

    Then you can use the following Jquery to call the service:

    <script type="text/javascript">
            var SyncParam = { SyncKey: "*****", StartDate: "*****",IsFullSync:"*****" }
            $.ajax({
                type: "POST", 
                url: "http://......Service.svc/GetStoreStatus",
                cache: false,
                data:JSON.stringify(SyncParam),
                contentType: "application/json; charset=utf-8",
                dataType: "json",      
                processData: true,
                success: function (msg) {
                alert(JSON.stringify(msg));
                },
                error: function (err) {
                    alert("you are doing wrong");
                }
            })
           
        </script>

    Besides, the following article can also help you:
    #Consuming WCF REST Services using Jquery:
    http://www.codeproject.com/Articles/128478/Consuming-WCF-REST-Services-Using-jQuery-AJAX-Call .

    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.


    Wednesday, June 4, 2014 2:24 AM
    Moderator
  • Thnaks for your info, what will be the equivalent in xml instead of Json?
    Wednesday, June 4, 2014 7:40 AM
  • Thnaks for your info, what will be the equivalent in xml instead of Json?

    Hi,

    For passing the xml data, please try to check this article which can help you:
    #Pass xml to WCF Rest Service:
    http://javascripterrors.blogspot.com/2011/08/pass-xml-to-wcf-rest-service.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.


    Wednesday, June 4, 2014 7:57 AM
    Moderator