views:

194

answers:

2

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 specifically intended for this ?

+4  A: 

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.

David Hogue
If i create a separate API controller then i have nothing to worry about with future changes. With mvc Routing Controllers i can always make sure the address i expose will be the same regardless inner changes i will make...Thanks! :)
gillyb
A: 

A web service would expose a WSDL.

Martin