none
Convert WCF soap to rest RRS feed

  • Question

  • Hi All,

    I was able to make a WCF soap working with your help:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/aba58d4f-e583-45a9-9183-411ad7aa1987/using-wcf-test-client?forum=wcf

    Now, we want to use the WCF as rest with json format return. Do I need to convert soap to rest?

    Can i configure both soap and rest?

    How can I do any of these options? and How can I test rest?

    Thanks,

    John

    Saturday, June 23, 2018 7:24 AM

Answers

  • It's my mistake to modify the fist code based on your code, you should use Post instead of Get since you need to pass an object to the backend.

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by JFBconsul Friday, June 29, 2018 7:55 PM
    Thursday, June 28, 2018 6:05 AM

All replies

  • I found a simple example of WCF rest:

    https://www.youtube.com/watch?v=AMO6aIXRp1U

    I will try to test.

    Saturday, June 23, 2018 7:54 AM
  • Hi JFBconsul,

    >>Can i configure both soap and rest?

    You could configure both SOAP and Rest by adding rest endpoint.

    I suggest you refer link below:

    #REST / SOAP endpoints for a WCF service

    https://stackoverflow.com/questions/186631/rest-soap-endpoints-for-a-wcf-service

    Best Regards,

    Tao Zhou

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 25, 2018 5:32 AM
  • Thanks for your reply and help Tao.

    Great Link, I have one issue: My parameter is a class as:

    [DataContract()]
        public class Mob_OrdenIn
        {
            [DataMember]
            public String Auth_token { get; set; }   
            [DataMember]
            public String Security_id { get; set; }
            [DataMember]
            public String Short_name { get; set; }
            .....

    My function is declared as:

     public Mob_OrdenOut Mob_AddOrder(Mob_OrdenIn pInput)
            {.....

    And the service declaration as:

     [OperationContract]
            [WebInvoke(Method ="GET", UriTemplate = "/MOB_OrderOut/{pInput}", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
            Mob_OrdenOut Mob_AddOrder(Mob_OrdenIn pInput);

    I got an error saying that pInput is not string. Any ideas in how to solver this?

    Thanks!

    Tuesday, June 26, 2018 8:21 AM
  • Hi JFBconsul,

    For "Mob_AddOrder", you should not use "pInput" in the URL Template.

    How will you request this rest service?

    You need to change your code like below:

    [OperationContract]
            [WebInvoke(Method ="GET", UriTemplate = "/MOB_OrderOut", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
            Mob_OrdenOut Mob_AddOrder(Mob_OrdenIn pInput);

    And then when requesting this api, you need to send Mob_OrdenIn in the request body.

    Here is a demo from PostMam.

    Code:

            [OperationContract]
            [WebInvoke(Method = "POST",
            RequestFormat =WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Bare,
            UriTemplate = "GetDataUsingDataContract")]
            CompositeType GetDataUsingDataContract(CompositeType composite);
    

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, June 27, 2018 7:29 AM
  • I think I was confuse Tao, the second part is your example, okay... let me try this.

    Thanks !

    Wednesday, June 27, 2018 9:42 AM
  • It's my mistake to modify the fist code based on your code, you should use Post instead of Get since you need to pass an object to the backend.

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by JFBconsul Friday, June 29, 2018 7:55 PM
    Thursday, June 28, 2018 6:05 AM
  • It worked nice Tao, thanks for your help!
    Friday, June 29, 2018 7:55 PM