Where Are We?
This chapter introduced the ASP.NET MVC framework and how you could create classes based on ActionResult to handle RESTful actions and responses. The ASP.NET MVC framework is based on the model-view-controller design pattern, or more accurately on the contemporary front controller pattern. The actions you create are directly mapped to URIs you design and provide to the URL routing subsystem the framework provides. This is a bit different from traditional ASP.NET, in which URLs are mapped directly to disk-based files.
The MVC framework has the capability to differentiate controller actions based on HTTP method by judicious application of the AcceptVerbs attribute, and you can disambiguate the action method names using the ActionName attribute.
The service logic itself is considered model code. The model in MVC terms is where the data access and business logic for your Web application is properly placed. I elected not to use a view to generate the HTML the service returned, but you certainly could if you chose to do so.
It’s at this point you might notice a pattern emerging. When working with pure ASP.NET, you need to provide quite a bit of infrastructure and “glue” logic. With the MVC framework, quite a bit of the infrastructure is provided for you. It’s more a matter of understanding what the framework provides and how to best fit your service into that framework.
The next chapter, however, shows you how to use the Windows Communication Foundation (WCF) to implement RESTful services, and by using WCF you implement even less boilerplate infrastructure, allowing you to concentrate nearly entirely on the core service functionality. WCF is also very much more configurable, allowing you to tailor your service’s behavior even after it has been deployed.