bal*_*dre 6 asp.net-mvc wcf web-services asp.net-mvc-2
我需要提供(对我自己)从数据库中获取一些数据的方法,以便我可以轻松地构建静态html页面,这样我就可以减轻处理它们的服务器(因为我每天浪费80Gb的带宽).
我的问题很简单
我应该创建一个WCF服务(或ASMX Web服务)来提取这些数据(WCF将在同一台服务器上,所以我仍然使用它,但更少,因为我只是得到我真正需要的东西,不要浪费处理页面)
或者我应该创建一个简单的控制器,如:
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("...");
}
}
Run Code Online (Sandbox Code Playgroud)
并且直接从我将使用的任何Javascript框架中调用它(错误,当然我可爱的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 =更灵活,可能更容易设置,但没有硬合同 - 如果你改变Json的格式,你的客户可能会在没有你最初注意到它的情况下破坏,所以它可以更多地跟上东西.
总的来说,我使用MVC,除非我有理由使用上面概述的WCF(客户端和服务器之间的稳定/保证/可发现合同的要求,要求使用SOAP,或者设置IIS网站时不方便/不必要)因为我的服务器作为Windows服务运行)
| 归档时间: |
|
| 查看次数: |
3933 次 |
| 最近记录: |