client for WCF Rest service
-
Wednesday, March 07, 2012 8:16 PM
What is best way of developing client for wcf services exposing json
what are pros and cons of using
asp.net web forms
asp.net mvc
java script
All Replies
-
Thursday, March 08, 2012 9:53 AM
Once you have a WCF Rest service, any type of client can consume it as it works on just HTTP verbs.
Even if you try to browse the REST service from IE (WebGet methods) you would get back a response.
Depending on your requirements it would be best to decide on web forms or MVC or javascript as each of them have their own pros and cons.
Rajesh S V
- Marked As Answer by Yi-Lun LuoModerator Wednesday, March 14, 2012 9:36 AM
-
Monday, March 12, 2012 6:46 AMModerator
Hi chintapali,
As for WCF REST style service(either JSON or XML response format), you can consume it in either strong-type client(like c# .NET, JAVA) or script client like ASP.NET AJAX or Jquery based web page.
For .NET specific client, you can use WebChannelFactory to access WCF REST service like a standard WCF service with ServiceContract and DataContract type defined:
#WebChannelFactory(Of TChannel) Class
http://msdn.microsoft.com/en-us/library/bb908674.aspx#WebChannelFactory inside a WCF Service
http://blogs.msdn.com/b/pedram/archive/2008/07/19/webchannelfactory-inside-a-wcf-service.aspx
or you can just use WebRequest like client to access it with raw HTTP requests and manually parse the response data stream(XML or JSON format):
#Stand-Alone JSON Serialization
http://msdn.microsoft.com/en-us/library/bb412170.aspx#How to: Serialize and Deserialize JSON Data
http://msdn.microsoft.com/en-us/library/bb412179.aspxAnd if you try accessing the REST service from web page script (in the same web app with the WCF service), JQuery is recommended as it has well encapsulated API for making HTTP AJAX requets.
#jQuery AJAX calls to a WCF REST Service
http://www.west-wind.com/weblog/posts/2008/Apr/21/jQuery-AJAX-calls-to-a-WCF-REST-Service#Consuming a WCF / ASMX / REST Service using jQuery
http://www.codeproject.com/Articles/59551/Consuming-a-WCF-ASMX-REST-Service-using-jQueryPersonally, for JSON format response, javascript(JQuery) based client is recommended since you do not need to care about deserialization works. Because the response data can be simply converted to JSON objects without defining datacontract types. While for strong-type client like .NET, you need to define the certain data contract types first and use serializer to deserialize JSON data stream into the defined types instances.
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Putting communities in your palms. Launch the browser on your phone now, type aka.ms/msforums and get connected!
- Marked As Answer by Yi-Lun LuoModerator Wednesday, March 14, 2012 9:36 AM

