开发者

Why use WCF REST when you have JsonResult in ASP.NET MVC?

I'm building an ASP.NET MVC application and still consider myself new to ASP.NET MVC. I come from a WCF REST background, so I initially set up a number of services that my jQuery-based client would call via RESTful AJAX requests. As I learned more about ASP.NET MVC, I discovered the JsonResult ActionResult type, and I can just add these methods to a controller and it behaves just like my WCF RESTful services.

So my question is, is there a limitation to JsonResults that I'm not seeing that WCF RESTful services provides? So far, I haven't seen it and am wondering if this completely eliminates my need for WCF REST functionality.

开发者_JAVA技巧

Thanks in advance!


Not everyone is building ASP.NET MVC applications.... not everyone is even building ASP.NET in any shape.

WCF REST is a service technology totally independent of ASP.NET or web - you can have WCF REST services without IIS in sight.


In your case, I'd go with MVC for my REST implementation, but to answer your question:

MVC ASP.Net is built to be HTTP only. REST is not. Representational State Transfer, or REST, while most commonly defined over HTTP, is not limited to HTTP. WCF allows you to communicate over non-HTTP connections.

Outside of that, I'd agree that it's easier and more robust to implement REST in MVC and especially in the newer MVC Web API stuff, but that said, REST has its place in WCF as well, because WCF can stand on it's own without HTTP.

EDIT: Also it should be noted that WCF can stand on it's own without IIS.


While it is technically true that REST != HTTP, the majority of REST services are using HTTP. And Microsoft are merging their WCF HTTP/REST stack into ASP.Net. Check out this page from the WCF codeplex site:

http://wcf.codeplex.com/wikipage?title=WCF%20HTTP

And this page

http://wcf.codeplex.com/discussions/319671

The upshot of this is that if you want to get the most up to date HTTP REST support you should definately shift to the new ASP.Net Web API which is shipping with ASP.Net MVC 4.

Using this approach, your services can work in IIS (obviously) but can also be self hosted if you like.

Also, if you have any investments in WIF with your exsiting WCF services (e.g. custom authentication/authorization manager classes, custom token handlers etc.) they will move easily from WCF to ASP.Net.

Finally, MVC 4 is open source, and taking community input, so it will be fast moving and high quality, and the risk of MS leaving you stranded by discontinuing is much less.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜