Sunday, January 6, 2013


REST-based WCF services – and the masters of the universe!

The WCF framework is around us for quite a while now. Microsoft has amended the WCF framework to expose the WCF services as the REST based service using special attributes. The REST service can be accessed as easily as accessing the URL. Let’s have a look at some practical applications of REST based services. The explanation of the basics of the REST based services is out of the scope of this post. However we can get the information about it on external websites.

Creating REST based service using Visual Studio.NET
The creation of the REST based service is very similar to WCF service. The WCF service can be made REST based WCF service by applying the attribute [WebGet] on the WCF service function. The WebGet takes the parameter with the name UriTemplate that identifies the URL format to access the function.
The REST based service uses webHttpBinding for the service endpoint.

Server:


Client:



REST Service: “I have the power of the universe!”
The REST based service can seamlessly integrate any client with the server easily. The client could be a .NET client or the smart phone application. For this post, let’s discuss how the smart phone client can integrate with the REST based endpoint of the WCF service. There are various platforms available to program the smart phone applications. The most widely amongst them are iOS, Andriod and Windows Phone. These programming platforms provide the wide range of libraries to connect to the web service endpoints.  The typical application on the phone sends the request to the service and receives the data from the server in the serialized format (JSON & XML) known as response packet. The phone application deserializes the JSON/XML packet and displays the data on the application. The entire scenario is a very good example of disconnected application that involves client and server.  
The phone application can also help to perform CRUD operations using GET/POST verbs on REST-based endpoint. The typical scenario can be discussed as follows:

1.  GET (Used to fetch the records from the database):


2.  POST (Used to insert the record into the database)


The REST based service is very easy way with which the client applications written using the different platforms can communicate with the server to receive the data from the server. This communication becomes possible using serialization of the data. It is analogous to accessing the webservice using SOAP request and response packets. The webservice uses XML serialization whereas phone application widely uses JSON serialization.  The programming of the REST based service has just gained enough space in the server programming because it is easier to integrate with phone and hand-held devices. Now it is very easy for your phone to answer your questions like "find me the thai restaurants near my area", "write few reviews of some movie from your phone which can be seen on the website".  There is lot more to come in this space!

Stay connected!

No comments: