Wednesday, September 01, 2010

Create RESTful WCF Service API : Step By Step Guide

Introduction
Windows Communication Foundation (WCF) is an SDK for developing and deploying services on Windows. WCF provides a runtime environment for your services, enabling you to expose CLR types as services, and to consume other services as CLR types. In this article I am going to explain you how to implement restful service API using WCF 4.0 . The Created API returns XML and JSON data using WCF attributes.
What is REST?
Based on Roy Fielding theory "Representational State Transfer (REST), attempts to codify the architectural style and design constraints that make the Web what it is. REST emphasizes things like separation of concerns and layers, statelessness, and caching, which are common in many distributed architectures because of the benefits they provide. These benefits include interoperability, independent evolution, interception, improved scalability, efficiency, and overall performance."
Actually only the difference is how clients access our service. Normally, a WCF service will use SOAP, but if you build a REST service clients will be accessing your service with a different architectural style (calls, serialization like JSON, etc).
REST uses some common HTTP methods to insert/delete/update/retrive infromation which is below:
a) GET -  Requests a specific representation of a resource
b) PUT - Create or update a resource with the supplied representation
c) DELETE - Deletes the specified resource
d) POST - Submits data to be processed by the identified resource
Why and where to use REST?
Few days back i was writing a service which was suppose to access by heterogeneous language/platform/system. It can be used by iPhone, Android, Windows Mobile, .NET web application, JAVA or PHP. Using web service it was bit complex for me to expose it to everyone using uniform system. Then we decided to use REST, which was easily espoused over cloud. This was a great example which shows the capability of SIMPLE RESTful SERVICE :) .  Below is some point which will help you to understand why to use the RESTful services.
Read more: Codeproject