Joe Doyle's Blog

What’s the best way to REST in .NET?

The more I hear about RESTful implementations, the more I believe it’s the most flexible way to expose the web interface for our project. It also allows for a built-in API of sorts to access our data in case our customers want to act on it in some way. Now the next step. How exactly do I create a RESTful web service in .NET? WCF appears to be Microsoft’s recommended method, but ASP.NET MVC looks like it could also do the job. And then there’s the WCF REST Starter Kit.

I was able to get a test service running using pure WCF and some samples I found on the web. Since our access will always be read-only, things were pretty simple. What I haven’t figured out yet is security. I want to be able to authenticate the user, then based on the username, either allow or deny access to the results. It’s also not immediately apparent how I can return a stream to mimic a file download. I ordered a copy of RESTful .NET which should help to fill in some of the parts I’m missing.

I’ve gone through the ASP.NET MVC 1.0 book and learned a lot. It really looks like a simple way to not only implement a REST service, but also allow for human-readable pages as well if I want. The book also provided examples for authentication and returning streams/byte arrays.

I’m tempted to prototype it out in ASP.NET MVC to get a feel for the differences compared to my poking and prodding of REST in WCF.