none
How to consume wcf json service using uri RRS feed

  • Question

  • Hi

    Hi ,I have below service i want to consume the service in json format can u guide me and passing parameters

     [WebGet(ResponseFormat = WebMessageFormat.Json)]
           

    List<String> GetBooksList();


            [OperationContract]
            [WebInvoke(UriTemplate = "{name}")]
            string AddBook(string name);

            [OperationContract]
            [WebInvoke(UriTemplate = "/UpdateBook/",Method="PUT",BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
            void UpdateBook(string id, string name);

            [OperationContract]
            [WebInvoke(UriTemplate = "DeleteBook/{id}",RequestFormat=WebMessageFormat.Json)]
            void DeleteBook(string id);

       
    Friday, October 4, 2013 5:20 AM

Answers

  • You can use HttpWebRequest or WebClient class to consume REST WCF Service

    http://debugmode.net/2011/05/15/wcf-rest-service-with-josn-data/


    Gaurav Khanna | Microsoft VB.NET MVP | Microsoft Community Contributor

    Friday, October 4, 2013 6:22 PM
  • Hi,

    For your service, we cannot consume it with a client generated by a tool such as Add Service Reference or svcutil.exe. If you have the same contract in the client code, you can use a class such as ChannelFactory<T> or WebChannelFactory<T> to create a proxy to talk to the service, or you can handcraft the requests and send it to the service using a general-purpose HTTP client.

    The following link will show the sample code about how to consume a JSON endpoint with both the WebChannelFactory<T> and a "normal" HTTP client (WebClient), please try to refer to:

    #How to consume wcf json service:
    http://stackoverflow.com/questions/14945653/how-to-consume-a-json-wcf-service-in-c-sharp .

    Best Regards,
    Amy Peng


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.



    Monday, October 7, 2013 2:47 AM
    Moderator

All replies

  • You can use HttpWebRequest or WebClient class to consume REST WCF Service

    http://debugmode.net/2011/05/15/wcf-rest-service-with-josn-data/


    Gaurav Khanna | Microsoft VB.NET MVP | Microsoft Community Contributor

    Friday, October 4, 2013 6:22 PM
  • Hi,

    For your service, we cannot consume it with a client generated by a tool such as Add Service Reference or svcutil.exe. If you have the same contract in the client code, you can use a class such as ChannelFactory<T> or WebChannelFactory<T> to create a proxy to talk to the service, or you can handcraft the requests and send it to the service using a general-purpose HTTP client.

    The following link will show the sample code about how to consume a JSON endpoint with both the WebChannelFactory<T> and a "normal" HTTP client (WebClient), please try to refer to:

    #How to consume wcf json service:
    http://stackoverflow.com/questions/14945653/how-to-consume-a-json-wcf-service-in-c-sharp .

    Best Regards,
    Amy Peng


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.



    Monday, October 7, 2013 2:47 AM
    Moderator