Joydip Kanjilal is a Microsoft MVP in ASP.NET and author of numerous books on Windows programming. He can be contacted at firstname.lastname@example.org.
- Enterprise architects challenged to manage data explosion
- Enhance and Optimize your Mobility/BYOD Infrastructure
- Research: Federal Government Cloud Computing Survey
- SaaS 2011: Adoption Soars, Yet Deployment Concerns Linger
- Advanced Threat Protection For Dummies ebook and Using Big Data Security Analytics to Identify Advanced Threats Webcast
- How to Protect Your Content and Improve Security with Cloud Client Computing and Thin/Zero Clients
REST, short for "Representational State Transfer," is an architecture paradigm for creating scalable services. A RESTful Web Service is one that conforms to the REST architecture constraints. Microsoft's Windows Communication Foundation (WCF) is a service-oriented framework that can be used to expose a RESTful service. A RESTful Web Service exposes resources URIs, then uses the HTTP methods to perform CRUD operations. In this article, I examine the basic principles of REST, explain what a RESTful service is, and show how a RESTful Service can be exposed using Windows Communication Foundation.
The code examples I present here and the downloadable source code that accompanies this article are implemented using Visual Studio 2010 and C# 4.0. To interact with the code examples in this article, you need to have Visual Studio 2010 installed in your system.
Representational State Transfer (REST)
Again, REST is an architectural paradigm in which an application's state and functionality is divided into resources which in turn is addressable using URIs over HTTP. A REST-based model is stateless, client-server based, cacheable and uses resources that have a common interface and are uniquely addressable.
Resources in a REST-based mode model are used to represent state and functionality and identified using logical URLs. Although REST is based on the stateless HTTP protocol, resources are cacheable -- you can also set expiration policies for your cached data. In a typical REST-based model, the client and the server communicates using requests and responses -- the client send a request to the server for a resource which in turn sends the response back to the client.
A request in a REST-based model contains an Endpoint URL, a Developer ID, Parameters and the Desired Action. The Endpoint URL contains the complete address of the script. The Developer ID is a key which identifies each request origin and is sent with each request. You can pass Parameters to a REST request just as you do with your method calls in any programming language. The Desired Action in a REST request is used to denote the action to be performed for the particular request.
Here's what a typical REST request URL looks like:
In the above request, the endpoint is http://localhost/sales, the action desired is search, and the developer key is 17. What follows next in the above URL is the type and keyword parameters.
An example SOAP request is shown below:
<?xml version = "1.0"?> <soap:Envelope> xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <soap:body s="http://localhost/sales"> <s:GetSalesDetails> <s:ProductID>1</s:ProductID> </s: GetSalesDetails > </soap:Body> </soap:Envelope>
The following code snippet illustrates how the above SOAP request can be represented using REST: