开发者

mvc return Json() vs. JSON based Web Service

开发者 https://www.devze.com 2022-12-17 16:55 出处:网络
I want to expose a service on my site that any users can call and get a JSON response. In the end, I want the users to be using this service as much as possible.

I want to expose a service on my site that any users can call and get a JSON response. In the end, I want the users to be using this service as much as possible.

My site is created using the asp.net MVC framework and i was wondering whats the best way to do this...

I think most would say it's obvious to use a web service (*.asmx) that returns JSON format, but i know that I can just create a url that users can call and have it return JSON format as well (e.g: calling "http://mysite.com/GetList" would return JSON list). In asp.net, using the return Json() method.

What are the advantages/disadvantages doing it this way vs. a Web Service which is specific开发者_运维知识库ally intended for this ?


I don't know that most would say use a .asmx web service. Personally I haven't made a .asmx web service in a while and I would go for the MVC approach. The only things I'd be worried about would be:

  1. future changes to the data, url, and/or parameters passed in.
  2. Making the controller too big or cluttered, in which case you could create a separate API controller.

To me the advantages are that it's more consistent with the rest of your app, it's simple and easy to work with, and there's not much to configure.


A web service would expose a WSDL.

0

精彩评论

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

关注公众号