Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Would it be better to use Asp.net mvc or web services?

I have asp.net mvc app written a couple of years ago and the more I add to it, I tend to make REST/AJAX calls to the controller to get data from it.

My question is do I carry on working in this way or should I expose the data as a separate REST services (WCF way of doing things)?

It feels that the boundary on what a mvc app is designed to do and the design of web service is getting blurred. The Mvc app (apart from separation) initially produced web pages, now it is being used to provide service based data.

JD

like image 435
JD. Avatar asked Aug 25 '11 08:08

JD.


People also ask

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 Web API is better than MVC?

Web API helps to build REST-ful services over the . NET Framework and it also supports content-negotiation(it's about deciding the best response format data that could be acceptable by the client. it could be JSON, XML, ATOM or other formatted data), self-hosting which are not in MVC.

Is ASP.NET MVC outdated?

ASP.NET MVC is no longer in active development.

Which is better Web forms or MVC?

Asp.Net Web Form has built-in data controls and best for rapid development with powerful data access. Asp.Net MVC is lightweight, provide full control over markup and support many features that allow fast & agile development. Hence it is best for developing an interactive web application with the latest web standards.


2 Answers

I see two possible scenarios

Single web app. In this case you carry on adding methods to the controller. This is good because it keeps relevant to the controller functionality in one place and will save you time. It is not suitable if the controller is being called from another web application. Simple, ugly but works, takes little time for development and much time for maintenance.

Web app + web service. You can segregate data retrieval methods into the service interface. The positive side is that you system becomes much more modular and independent, which is good for maintenance. If you predict that there will be other methods that will be added soon or if the methods are used by other web applications, then this path is probably better than extending the current web app. The negative side is that the new service will require some refactoring to the current web application and will take time to be developed/tested etc. This decision brings more complexity, but makes your application easy to be extended.

like image 89
oleksii Avatar answered Sep 18 '22 23:09

oleksii


I think WCF has several advantages over MVC if you are strictly sending data, specifically in terms of data formats being unambiguous (SOAP vs. using home-brewed encodings), industry-wide tool support, excellent support for different types of bindings (i.e. not just HTTP), various transport level services, nice logging and tracing capabilities, etc.

In the end though, it boils down to: is there a significant enough advantage to going with WCF for your case. That is something that you'd have to figure out yourself.

like image 27
Daniel B Avatar answered Sep 21 '22 23:09

Daniel B