If you are planning to get started with REST in WCF, the following information might be helpful.
What is REST?
Representational state transfer (REST) is a style of software architecture for distributed hypermedia systems such as the World Wide Web. As such, it is not strictly a method for building “web services.” The terms “representational state transfer” and “REST” were introduced in 2000 in the doctoral dissertation of Roy Fielding, one of the principal authors of the Hypertext Transfer Protocol (HTTP) specification.
REST strictly refers to a collection of network architecture principles which outline how resources are defined and addressed. The term is often used in a looser sense to describe any simple interface which transmits domain-specific data over HTTP without an additional messaging layer such as SOAP or session tracking via HTTP cookies. These two meanings can conflict as well as overlap. It is possible to design a software system in accordance with Fielding’s REST architectural style without using HTTP and without interacting with the World Wide Web. It is also possible to design simple XML+HTTP interfaces which do not conform to REST principles, and instead follow a model of remote procedure call. The difference between the uses of the term “REST” therefore causes some confusion in technical discussions.
Systems which follow Fielding’s REST principles are often referred to as “RESTful“.
What are RESTful Web Services?
A RESTFul web service is a simple web service implemented using HTTP and the principles of REST. Such a web service can be thought about as a collection of resources. The definition of such a web service can be thought of as comprising three aspects:
- The URI for the web service such as
- The MIME type of the data supported by the web service. This is often JSON , XML or YAML but can be anything.
- The set of operations supported by the web service using HTTP methods (e.g. POST, GET, PUT or DELETE).
Members of the collection are addressed by ID using URIs of the form <baseURI>/<ID>. The ID can be any unique identifier. For example if a RESTFul web service representing a collection of cars for sale might have the URI
http://example.com/resources/cars. f the service uses the car registration number as the ID then a particular car might be present in the collection as
The following table shows how the HTTP verbs are typically used to implement a web service.
|Collection URI such as
||List the members of the collection. For example list all the cars for sale.||Not generally used. Meaning defined as replace the entire collection with another entire collection.||Create a new entry in the collection where the ID is assigned automatically by the collection. The ID created is typically returned by this operation.||Not generally used. Meaning defined as delete the entire collection.|
|Member URI such as
||Retrieve the addressed member of the collection||Update the addressed member of the collection or create it with a defined ID.||Not generally used.||Delete the addressed member of the collection.|
What are WCF Rest Services?
WCF Rest Services are normal WCF Services that have added functionality so that they can be consumed in a RESTful manner (URI vs URL, Usage of HTTTP Verbs, Usage of Different Data Transfer Formats like JSON, YAML, etc…). So for example, if you had a stock ticker web service that you built in WCF, instead of requiring the caller to use a heavy WSDL implementation and ASMX, you could just use the WCF Rest functionality to publish that service as a JSON service instead and have it consumed via AJAX without having to point to an ASMX resource.
An example of WCF REST Service in .Net Framework 3.5:
WCF 3.5 provides explicit support for RESTful communication using a new binding named WebHttpBinding.
The below code shows how to expose a RESTful service
int GetStock(string StockId);
Microsoft has released a white paper in early 2007 comparing different distributed communication technologies with WCF. (including REST Services).
You can download this whitepaper from here (http://msdn.microsoft.com/en-us/library/bb310550.aspx)
Though there are loads of information on REST these days, i found the following links to be very insightful and helpful in understanding this technology.
An Introduction to WCF Restful Web Services by Jon Flanders in MSDN Magazine Jan 2009
A Guide to Designing and Building Restful Web Services using WCF 3.5 by Aaron Skonnard on MSDN in Oct 2008
WCF Blog Series:
- REST in WCF – Part I (REST Overview)
- REST in WCF – Part II (AJAX Friendly Services, Creating The Service)
- REST in WCF – Part III (AJAX Friendly Services, Consuming The Service)
- REST in WCF – Part IV (HI-REST – Exposing a service via GET – Configuring the service)
- REST in WCF – Part V (HI-REST – Exposing a service via GET – The ServiceContract and Implementation)
- REST in WCF – Part VI (HI-REST – Consuming our GET service via AJAX)
- REST in WCF – Part VII (HI-REST – Implementing Insert and Update
- REST in WCF – Part VIII (HI-REST – Implementing Delete)
- REST in WCF – Part IX – Controlling the URI
- REST in WCF – Part X – Supporting Caching and Conditional GET
Screencast Series on Channel9:
- endpoint.tv – Controlling the URI in RESTful WCF with Rob Bagby
- deCast – Creating a HI-REST GET Service with WCF 3.5
- deCast – Consuming a HI-REST GET Service From Silverlight 2 (Beta 2)
- endpoint.tv – Caching and Conditional Get with Rob Bagby
- deCast – Creating an AJAX-Friendly WCF Service
- deCast – Creating a HI-REST PUT Service That Exposes Insert and Update
- endpoint.tv – Securing RESTful services with ASP.NET Membership
- endpoint.tv – Content Negotiation with RESTful services
- deCast – Tunneling a PUT through POST with RESTful WCF
REST and WCF 3.5 – Adnan Masood (LEVEL 200)
VS 2008, WCF and REST – (Level 200)
REST and ASP.Net MVC – Brian Hitney (Level 200)
REST and ADO.Net Services – Chad Brookes (Level 200)
MSDN Code Samples:
For further queries on troubleshooting and general advice, you can also check out REST Forums from MSDN.