WCF vs IHttpHandler

Description Article

A pure ReST web service must be implemented using a IHttpHandler-derived class. The use of the WCF framework hides most of the manual work.


The IHttpHandler provides only a single entry point – ProcessRequest – for processing all incoming HTTP requests. In order to implement the RESTful interface, the implementation of the ProcessRequest method will have to perform the following tasks:

  1. Inspect the incoming URI and figure out which resource it identifies;
  2. Extract any variables found within the URI and map them to code variables;
  3. Verify authentication of the user responsible for the request;
  4. Determine the HTTP method used in the request and whether it’s allowed for the resource;
  5. Read the resource representation found in the entity body (if any);
  6. Use all of this information to perform the underlying service logic;
  7. Generate an appropriate HTTP response, including the proper status codedescription, and outgoing resource representation in the response entity body (if any);

WCF provides a programming model,  that shields from several aspects of this code:

1. It shields from most HTTP protocol details;
2. It shields from URIs details and the resource representations transmitted on the request, by providing a built-in URI template programming model that makes it easy to match URIs and extract variables.This is possible due to:
2.1. A new set of attributes for mapping HTTP method + URI template combinations to method signatures;
2.2.  Several serialization improvements for supporting different types of resource representations (XML and JSON).

The “WCF ReST Programming Model” is encapsulated on the System.ServiceModel.Web.dll assembly.

[1] Refer to the Service Development article for details of the WCF web programming model.

[2] Refer to the A Guide to Designing and Building RESTful Web Services with WCF 3.5 article of the MSDn documentation for Microsoft details of the WCF web programming model on 3.5.

[3] Refer to the A Developer’s Introduction to Windows Communication Foundation 4, Improments ReST Support article of the MSDN documentation for Microsoft details of the WCF web programming model on 4.0.