Creating a RESTful Web Service Using ASP.Net MVC Part 1 - Introduction

September 27, 2008 00:18 by Admin

My View of a RESTful Web Service

Early in 2008 I attended a presentation by Tim Ewald in which he introduced his take on RESTful web services. I’d come across them before, but he provided the momentum for me to look more closely at them. I spent some time reading around the idea and bought the bible on the subject, RESTful Web Services.

I’m not going to address the REST versus SOAP argument (just try REST v SOAP in Google). Suffice to say I can see a lot of benefits in taking a RESTful approach and am keen to investigate further.

There aren’t really standards in the REST world, rather a number of conventions. Different web services have taken a pragmatic approach to how far they go towards the ideals of a RESTful web service. That pragmatism has perhaps helped RESTful web services to become one of the most widely used techniques for getting applications talking together over the internet.

For this series of posts I’m going to assume a RESTful web service would have these features:

  • Based around resources;
  • Each resource is addressable through a URI;
  • Each resource supports the same Uniform Interface consisting of a low number of methods;
  • Multiple representations for the same resource are possible;
  • The service has a high degree of connectedness (i.e. representations contain links to other resources);
  • It is stateless (by which I mean each request is dealt with in isolation... I don’t mean the web service cannot store the state of resources in some database).

Implementation Approach

Back in February 2008, I was spending most of my time working in the Microsoft Visual Studio 2005 world. So for my purposes, if a RESTful web service was going to go beyond the drawing board, it would need to live within IIS / ASP.Net and be written in C#.

ASP.Net 2.0 makes creating SOAP based web services easy, but there is no out of the box support for a REST based approach. It would have been possible to write something from scratch, but I didn’t have the time.

We are a few months on and I can relax my criteria a little to allow VS2008. This means I can consider Windows Communication Foundation (WCF) which now supports REST web services. Another option is the ASP.Net MVC previews, which started to be released late last year. This new framework, at the very least, would help with the “addressable through a URI” feature.

As of a couple of weeks ago, Preview 5 of the MVC was released. This includes a feature to route requests according to the HTTP method used… previously possible with the Simply Restful Routing contribution to the MVCContrib project by Adam Tybor, but apparently now baked in. Reading about this new feature got me itching to make time and investigate properly.

What I Hope To Achieve

So what am I to do about this itch? Well I’m going to see how many items on my feature list above I can get working using the ASP.Net MVC framework. Hopefully all of them, but as I start out I don’t actually know the answer.

Along the way I hope to find the “right” way to support each feature… and I’m not adverse to performing the odd U turn if a better solution crops up or is suggested. In fact I’m already working on the next post and have made a few changes of direction already!

One outstanding question… why am I not using WCF? After a quick once over I couldn’t see simple ways to do some of the things I wanted to achieve, e.g. multiple representations. But most of all, this is being done on my time, I’ve used WCF before (it is very heavy weight and stiff) and MVC just seemed more appealing. Once I have completed this investigation, perhaps I will look into what I have to do to achieve the same in WCF.


Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading