Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which to choose: ASP.NET MVC or RESTful WCF?

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?

like image 213
Morgan Cheng Avatar asked Dec 08 '08 14:12

Morgan Cheng


People also ask

Which is better asp net or MVC?

ASP.NET requires less expertise than MVC and is much faster to develop web applications overall. Prior knowledge of HTML is not required. ASP.NET uses a more mature code-base and has a larger web control toolbox. It's more sensible to use ASP.NET if you are already relying on 3rd party UI controls.

Should I use MVC or Web API?

You should use Web API over ASP.Net MVC if you would want your controller to return data in multiple formats like, JSON, XML, etc. Also, specifying the data format in Web API is simple and easy to configure. Web API also scores over ASP.Net MVC in its ability to be self-hosted (similar to WCF).

Why use ASP Net Web API instead of WCF which suits better?

WEB API is a better choice for simpler, light weight services. WEB API can use any text format including XML and is faster than WCF. WEB API can be used to create full-blown REST Services. WEB API doesn't require any data contracts and doesn't require configurations to the level of WCF.

Why ASP.NET MVC is better?

The main advantages of ASP.net MVC are: Enables the full control over the rendered HTML. Provides clean separation of concerns(SoC). Enables Test Driven Development (TDD).


1 Answers

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.

like image 157
Jacob Avatar answered Oct 14 '22 20:10

Jacob