WebService or a simple MVC controller?

I need to provide (myself) a way to capture some data from a database so that I can easily create static html pages so that I can free the server from processing them (since I'm with a bandwidth of 80 GB per day).

My question is simple

should I create a WCF service (or an ASMX web service) to pull this data (WCF will be on the same server, so I still use it, although much less, because I just get what I really need and do not waste time processing pages)

or should I create a simple controller , for example:

public class ServiceApiController : Controller { public ActionResult GetPrizes(string calendarGuid) { return Json("..."); } public ActionResult GetWinners(string calendarGuid) { return Json("..."); } public ActionResult AddSubscriber(string calendarGuid, string[] args) { return Json("..."); } public ActionResult ReclaimSubscriberEmail(string calendarGuid, string email) { return Json("..."); } public ActionResult RequestContact(string calendarGuid, string[] args) { return Json("..."); } } 

and just name it directly from any Javascript Framework that I will use (err, of course, my lovely jQuery).

+6
web-services asp.net-mvc wcf asp.net-mvc-2
source share
3 answers

It depends. The WCF service is more flexible since you donโ€™t need to rely on HTTP and use direct TCP connectivity instead, and I find it very easy to make it expose SOAP. Just setting up web.config for behavior, endpoint, etc. A little harder than it should be.

MVC, on the other hand, is probably faster to set up because you donโ€™t have to deal with the fact that itโ€™s sometimes a little difficult to modify DataContracts (since they require redeploying the general assembly).

WCF = more "solid" with a much larger protocol to it, to make it "stable", that is: you can establish a tight contract between the Supplier and the Consumer.

MVC = is more flexible and possibly easier to configure, but without a hard contract - if you change the Json format, your clients may break if you do not notice it initially, so it is much more suitable.

In general, I use MVC if I have no reason to use WCF as described above (the requirement for a stable / guaranteed / detectable contract between the client and the server, the requirement for SOAP, or when it is inconvenient / no need to configure the IIS website, for example, because my server is running as a windows service)

+8
source share

I would prefer a web service if you do not need a user interface infrastructure to show some data.

0
source share

Personally, I would create a WCF web service to expose the data. It will be more flexible, and you can identify several endpoints that process different data formats JSON, XML, ... Thus, you can use the service with different clients (web, windows, mobile, ...).

0
source share

All Articles