Chuck, in a comment on a previous post, posed this question:  Why choose WCF for a REST app?  Here it is in full context:

I'm having a hard time justifying why I would use WCF for REST. It seems dead simple in ASP.NET (or any other web framework), yet obscure in WCF. There are two big problems I see, (1) Lack of good documentation and real examples for the Web Programming Model and (2) Why would I use an API that abstracts transport protocols for an architectural style built for a specific protocol?

Number 2 is a big one for me. I understand the goal of WCF is to have a service accessible in various ways, yet RESTful services seem to have a very specific set of constraints. For example, if I'm using a '301 redirect' as a response to a request, can I really make my service accessible via SOAP or any other transport protocol? Also, how do I write a '301 redirect' in WCF (simple things should be simple...)?

I'm going to keep trying to understand REST via WCF, but right now it seems harder than it should be.

My answer was this: Because you want the extensibility and flexibility of WCF.  

In more detail: if you need to do only a simple REST app, then WCF is probably not the right tool.  But if you need to do some REST, and some SOAP, and some heterogeneous system integration, and maybe some asynchronous connection., then WCF is starting to look better.  Even if you don't have mixed bag of communication protocols, if you like the "micro kernel" channel architecture of WCF with the extensibility capabilities (behaviors and so on), to do things like auditing, authentication and authorization, message transformation, streaming, and other things, then WCF might be the right REST tool for you. Even if you want none of that, if you would like the flexibility to choose your hosting mechanism, for example hosting a service in IIS, or in a Windows Forms app, or within a "headless" Windows Service, then WCF might be right for you.  

If you are doing only REST, and only simple cases, then I agree, there are simpler frameworks to accomplish this.  But WCF does a whole lot more.

A Real-World Example

Check out the video of the people at MySpace explaining how they used WCF for their REST interface, and why they chose WCF. For more on Myspace and their use of WCF, see Vittorio's post.  Couple of highlights:

  • They're expecting tens of millions of REST transactions per hour.
  • They would like Content-Type negotiation better supported in the framework; for now they use extensibility within WCF to get what they need.
  • They wanted a flexible authentication approach (for example using OAuth), and the WCF Channels made it "so easy".
  • They wanted to support "High REST" and "Low REST" (nod to Nelson Minar for coining the term), and again the Channel architecture in WCF made this very simple.

Cheers!