开发者

WebService or a simple MVC Controller?

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)


I would prefer the webservice, if you don't need any UI framework to show some data.


Personally I would create a WCF web service to expose the data. It will be more flexible and you could expose multiple endpoints handling different data formats JSON, XML, ... This way you could consume the service from different clients (web, windows, mobile, ...).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜