I need to provide (to myself) a way to grab some data from the database in order that I can easily build static html pages so I can relieve the server of processing them (as I'm having 80Gb of bandwidth wasted per day).
My question is simple
should I create a WCF service (or ASMX Web Service) to pull this data (WCF will be in the same server, so I still use it, though much less as I'm just getting what I really need and don't waste to process pages)
or I should create a simple controller like:
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 call it directly from whatever Javascript Framework I would use (err, off course my lovely jQuery).
Depends. A WCF Service is more flexible as you don't have to rely on HTTP and can instead use direct TCP Connectivity, also I believe it's really easy to have it expose SOAP. Just the web.config setup for behavior, endpoint etc. is a bit more complex than it should be.
On the other hand, MVC is possibly quicker to setup like that because you don't have to deal with the sometimes a bit hard to change DataContracts (as they require re-deployment of the shared assembly).
WCF = more "solid" with a lot more protocol to it to make it "stable", that is: You can establish a hard contract between Provider and Consumer.
MVC = more flexible and possibly easier to setup, but no hard contract - if you change the format of the Json, your clients may break without you initially noticing it, so it's a lot more keeping up with stuff.
Overall, I use MVC unless I have a reason to use WCF as outlined above (requirement for a stable/guaranteed/discoverable contract between client and server, requirement to have SOAP, or when it's inconvenient/unnecessary to setup an IIS Website, for example because my server runs as a Windows Service)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With