Representational State Transfer (REST) isn't SOAP based Service and it exposing a public API over the internet to handle CRUD operations on information. REST is targeted on accessing named resources through one consistent interface (URL). REST uses these operations and alternative existing options of the HTTP protocol:

  • GET
  • POST
  • PUT
  • DELETE

From developer's points of view, it's not as easy as handling the object based Module which is supported after we create SOAP URL as reference or create WSDL proxy.
But .NET will have class to deal with JSON restful service. This document will only cover "how to deal JSON response as a Serialized Object for READ/WRITE & convert JSON object into meanful Object".

In order to consumer JSON restful service , we'd like to do follow steps:

  1. produce the restful request URI.
  2. Post URI and get the response from “HttpWebResponse” .
  3. Convert ResponseStreem into Serialized object from “DataContractJsonSerialized” function.
  4. Get the particular results/items from Serialized Object.

This is very generic function which can be used for any rest service to post and get the response and convert in:
public static object MakeRequest(string requestUrl, object JSONRequest, string JSONmethod, string JSONContentType, Type JSONResponseType) { 
try { 
HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest; 
//WebRequest WR = WebRequest.Create(requestUrl);  
string sb = JsonConvert.SerializeObject(JSONRequest); 
request.Method = JSONmethod; 
// "POST";request.ContentType = JSONContentType; // "application/json";  
Byte[] bt = Encoding.UTF8.GetBytes(sb); 
Stream st = request.GetRequestStream(); 
st.Write(bt, 0, bt.Length); 
st.Close(); 

using(HttpWebResponse response = request.GetResponse() as HttpWebResponse) { 

if (response.StatusCode != HttpStatusCode.OK) throw new Exception(String.Format( 
    "Server error (HTTP {0}: {1}).", response.StatusCode, 
response.StatusDescription)); 

// DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(Response));// object objResponse = JsonConvert.DeserializeObject();Stream stream1 = response.GetResponseStream();  
StreamReader sr = new StreamReader(stream1); 
string strsb = sr.ReadToEnd(); 
object objResponse = JsonConvert.DeserializeObject(strsb, JSONResponseType); 

return objResponse; 

} catch (Exception e) { 

Console.WriteLine(e.Message); 
return null; 

HostForLIFE.eu ASP.NET 4.6 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.