Rinsing the SOAP from WCF (or, RESTful WCF Hyperlink Acupuncture)

August 12, 2008

.NET 3.5 SP1 stealthily went RTM yesterday, as I’m sure none of you have noticed. It’s a big, Roly Poly bug of image a service pack, and it comes with some nice enhancements to the REST oriented features introduced to WCF in version 3.5. Also included in SP1 is a tangential enhancement to WCF that removes the requirement to decorate DataContracts with WCF attributes.

First, for those of you sexy Web 2.0 Jockeys who could design a textbook REST API with your eyes closed and a pint of Johnny Walker coursing through your veins, I’ve provided a list of resources specifically about implementing REST services using WCF. There are also a few RESTish ASP.NET MVC links sprinkled in the mix, to add a little bit of flava.

Then, for REST neophytes such as myself, there are some resources to help you get your mind around the REST style itself, independent of WCF, which I highly recommend taking the time to do. Just as the use of SOAP Web Services does not magically transform your stinking rats nest of ad hoc, RPC style web services into a Service Oriented Architecture, simple use of XML or JSON over HTTP does not mean you are applying the REST architectural style. Not to imply that a stinking rats nest is bad, or that POX/JSON over HTTP is bad, it just isn’t necessarily RESTful.

None of the links presented here have much interest in the REST vs SOAP debate. There are trillions upon trillions of terabytes of available blather on REST vs SOAP and SOAP vs REST and Soapy REST vs Resting SOAP. If you want help deciding between the two, ask that scary looking guy in the corner there and he’ll show you to the REST vs SOAP room. Um, I would change out of the chaps first. Much better. (I will post one link though, to a podcast by Udi Dahan on the subject, because it is a pretty balanced discussion  and because it is sitting open in my browser and won’t cause me to do any extra typing. Fine, I lied, I’ll also link to an Information Week article about Web Oriented Architecture (WOA) and SOA that piqued my interest in the subject in the first place).

And now buckle up kids, here we go…

RESTful WCF

Zen of the Web Programming Model (Part 1) : Brain.Save()
Kirk Allen Evans’s Blog : Creating RESTful Services Using WCF
Kirk Allen Evans’s Blog : Creating a REST Twitter Client With WCF
More on RESTful Service with WCF and POX/POCO – Johan Danforth’s Blog

Ajax & RESTful WCF

Calling Web Services via AJAX – Part 1
Calling Web Services via AJAX – Part 2
jQuery AJAX calls to a WCF REST Service – Rick Strahl’s Web Log
WCF REST Configuration for ASP.NET AJAX and plain REST Services – Rick Strahl’s Web Log
CoDe Magazine – Article: REST-Based Ajax Services with WCF in .NET 3.5
Return JSON from a RESTful service

Speciality Topics

Dan Rigsby » REST Services and Metadata Endpoints in WCF
WCF, WebHttp Binding, and Authentication

Screencasts

InfoQ: Rob Windsor on WCF with REST, JSON and RSS

Not everyone’s experience with the REST support in WCF 3.5 has been like sucking sugar water from a humming-bird feeder though:

Using WCF for REST, Part 1, Part2 and Part 3. Make sure you read all the comments though, several of the gripes brought up in these posts have been addressed with SP1.

UriTemplate, UriTemplateTable
A must read reference document on MSDN describing in gory details how the UriTemplate works.

RESTful ASP.NET MVC

ASP.NET MVC: Using RESTful Architecture : Rob Conery
MS MVC: Simply Restful Routing | Adam Tybor’s Blog
Creating a RESTful POX Service using the ASP.NET MVC Framework [The .NET Addict's Blog]
Unifying Web "Sites" and Web Services with the ASP.NET MVC Framework | Aaron Lerch
ASP.NET MVC Tip #5 – Submitting an AJAX Form with jQuery – Mike Bosch’s Blog on .NET

This next one isn’t really about REST, but if you’re going to be creating a non-public REST API, you’re going to want to be using SSL as REST, not being a standard like SOAP, doesn’t have cool built-in encryption magic.

Steve Sanderson’s blog » Blog Archive » Adding HTTPS/SSL support to ASP.NET MVC routing

RESTful REST

RESTful Web Services | O’Reilly Media
This is a book by Sam Ruby and Leonard Richardson and is cited by just about every blogger that even has the word REST pop up their comments. And it was reviewed here. I have a copy on order, so I can’t tell you first hand how great it is, but I have read its praises many times today, so I am betting it is a very good place to start. As a bonus, the examples are mostly in Ruby – which I am ashamed to admin I’ve never actually learned to read, but maybe this is a perfect opportunity.

General RESTness
REST for the Rest of Us
REST for the Weary
Plain Old Stan: Understanding REST – a disgrace of Wikipedia definition

RESTful Services
RESTful Service – Ajax Patterns
Building Web Services the REST Way

RESTful API Design
Dustin R. Callaway – Design the REST API
Two Cardinal Sins of REST API Design: Lessons… from the NewsGator REST API
XML.com: How to Create a REST Protocol
Tarlog on Java: How to use SAML with REST Web Services

To (ASP.NET)MVC or not to MVC (or, ASP.NET MVC Hyperlink Acupuncture)

July 29, 2008

Currently, we are struggling with a decision as we stand at the edge of a new project and attempt to divine the future. Here are a few chicken bones, in the form of links:

Jeff Atwood is working with MVC, and is bothered by what he feels is the re-introduction of Tag Soup. Rob Conery begs to differ, and makes the case that if you are careful and organized you can easily avoid Tag Soup, and instead prepare a delicious Tag Cobbler. In the comments, readers suggest you can do Tag Cobbler one better and have yourself a nice, orderly, maintainable Tag Cake with some of the alternate view engine integrations provided in the MvcContrib project. (Or, maybe you like SharpTemplate.NET for its flexibility, but are dismayed that there is no default MVC integration in MvcContrib. Don’t worry, it is trivial to create the integration yourself.)

One of the most significant concerns with leaving your old ASP.NET station wagon running at a red light and jumping into the sexy new MVC convertible with  image imagethe hot blonde making eyes at you from the turning lane is the lack of rich UI controls for MVC. Classic ASP.NET may have drawbacks, of course, but one of its great strengths is the breadth of very well made user interface components to turn your ugly developer sensibilities into a beautiful and modern masterpiece in a plug n’ play way. We use Telerik controls here, but they aren’t ready to commit to an MVC suite yet. There is some advice on how to use user controls in ASP.NET MVC (and other ways to gracefully render content in MVC), but it will likely take some time before rich UI components are available for MVC, the framework is just so different. In the mean time you can make some third party controls work with MVC if they will function without postbacks or viewstate, and there is no particular reason your MVC application can’t link to a standard ASPX page with a full lifecycle if you only have a few places where you need some particularly web forms dependant control.

Another approach to server controls, though, is DHTML controls. There are a number of vendors and open source frameworks that provide rich grids, tree views, etc. purely using JavaScript and AJAX. These should work just fine with MVC without modifications. However, this won’t cover all your bases. For instance, I haven’t had much luck finding a Javascript calendaring / scheduling suite that can even come close to the server-control based Telerik or DevExpress offerings.

If you choose ASP.NET MVC

If you want to use jQuery to facilitate your AJAXiness, check out this blog post and associated download. And this one and subscribe to this blog. If you want to use jQuery for validation using MVC, read this. You may also want model-based validation that works server side AND client side. Here is a post providing links to both client side and server side validation techniques.

If you end up using the excellent extJS suite of JavaScript controls, you should check out Coolite, which wraps the extJS library with ASP.NET controls and will have MVC support shortly, and the project extsharp that uses Script#, a library that allows you to compile C# into JavaScript, to product a C# object model for working with extJS controls.

You will also want to check out the S#arp Architecture project on CodePlex by Billy McCafferty. This is a reference architecture for building an enterprise ASP.NET MVC application in a modern, domain driven style using NHibernate 2.0 as the ORM and dependency injection via Castle Windsor. I’m still in the process of going through the documentation, but this looks like a really solid place to start if you’re building an app from scratch. If you go the NHibernate route, take a look at this series of posts about using NHibernate, ASP.NET MVC, and Rhino Commons.

You’ll also want to follow the excellent blogs of Stephen Walther, Scott GuthrieJeffrey Palermo (who is writing a book for Manning on ASP.NET MVC, which you can read as its written via their
Early Access Program) and Rob Conery (who has produced quite the library of screencasts on building an ASP.NET MVC application using TDD). Oh, and Maarten Balliauw seems to have consistently high quality posts on MVC as well. He even came up with a nifty MVC Extension method to render a Data Grid with paging and editing capabilities using an extension method. Pretty slick.

ASP.NET MVC Lives Here, with helpful relatives in the granny unit, and has a summer home here.

[Update] There is an ASP.NET MVC “News, Announcements and Information”, aka buzz site, here at aspdotnetmvc.com that acts as a sort of giant ear to the ground picking up and aggregating any and all things MVC that pop up on the web. I don’t think it is just a dumb aggregator, though, I think it is human-filtered, so it is probably a good place to visit frequently or a good starting point for MVC research. I tried subscribing to the RSS feed once, but was almost immediately blown out of my seat by volume of aggregated posts, so I un-subscribed. But if you’re working with ASP.NET MVC, I’m pretty sure you’ll want this site on your short list of bookmarks, or, if you can withstand the torrent, you might even want to subscribe.

Want to create some services using MVC? Read this and this.

Want to create reusable controls for MVC? Read this and this.

Want to add HTTPS/SSL support to ASP.NET MVC routing? Here it is.

Want to run an ASP.NET MVC using an embedded web server as a desktop app? No? I don’t believe you. Read this.

For good measure, also check out this Digg clone built using ASP.NET MVC. They call it Kigg, so that you can’t say it out loud without feeling silly.

Steven Walther is building the self proclaimed Best Forum Application IN THE WORLD based on MVC. This is an ongoing series, currently at post 4 1/2. See
Part 1, Part 2, Part 3 , Part 4 and Part 4/12. In addition to technical MVC discussion, the series opens up with a very nice, ALT.NETy discussion of the the best way (from a process / practice point of view) to go about building the best forum app in the world.

You’ll probably also want to check out BlogSvc.net, and open source Blog Engine built using ASP.NET MVC. This is not a sample app but a full blown blogging platform that is built on AtomPub and uses LINQ, jQuery and other cool technology. The project website is here and the Codeplex home page is here.

More recently, Maarten Balliauw has posted another end to end sample called Car Trakkr, which is built on the Beta 1 release, so it’s nice and fresh.

 

If you stick with ASP.NET Web Forms

But you covet the pretty little .aspx-less URLs of MVC, read this.

Web Forms and MVC are not the only patterns on the block, BTW

Don’t forget about MVP. Many people prefer MVP (Model View Presenter) over MVC, and while the frothy, drunken buzz over ASP.NET MVC is rather deafening, there is a lot of support for doing MVP in ASP.NET, numerous open source frameworks supporting it, and it might be a good middle ground between the two approaches. If you’re going to use DDD and NHibernate and are interested in MVP, read this article and check out the “Enterprise Sample” that is included. Also by the same author (and the author of S#arp Architecture noted above) is this Code Project article and associated samples about building an MVP app in ASP.NET. Interestingly, the author has amended the article to recommend against rolling your own MVP, but if you choose the pattern, this is a good article to read anyway. Kyle Baley, the Coding Hillbilly, discusses how the redneck community views the difference between MVC and MVP.

You may also like to read this article about choosing a web framework for .NET.

And, lo and behold, Wordpress found this for me in the “this might be related” section: ASP.NET MVC vs Web Client Software Factory (which is MVP based)

Don’t Forget about Castle Monorail

And of course, ASP.NET MVC is the new kid on the block. The open source framework Castle Monorail has an established, mature MVC framework for ASP.NET. Interestingly the founder of Castle is going to work for Microsoft, but not for the ASP.NET MVC team.

Let me know if I left out anything critical, or you know of any good write-ups on the various options and the tradeoffs between them.