Asp.net-mvc – Which to choose: ASP.NET MVC or RESTful WCF

asp.net-mvcrestwcf

With ASP.NET MVC, it is common to have AJAX code(e.g. jQuery) to invoke web service from server to without page refreshing. It's natural to make web service RESTful. It seems that there are two ways to go. First, the ASP.NET MVC URI's are RESTful, it is very easy to make some Controller/Action to act as web service method. Second, WCF can be RESTful since version 3.5.

So, what is pros and cons of these two ways?

Requests to ASP.NET MVC will go through ASP.NET Pipeline. Does this make it slower than WCF?

Best Answer

If you're already using ASP.Net MVC for the rest of the website, I suppose it makes sense to use the same framework for the AJAX calls as well.

With regard to the ASP.Net pipeline, I assume you're worried about the whole Page Lifecycle thing. The page lifecycle is only executed if you use Views with the WebFormViewEngine. The framework provides JsonResult for easy JSON serialization of action results, which completely bypasses the ASP.Net page lifecycle. Similar classes are available for XML, RSS, etc.