1

We designing a new ASP.NET MVC application and we have user controls that we would like to bind with JSON data

1) we can implement a controller's action that returns JsonResult http://shashankshetty.wordpress.com/2009/03/04/using-jsonresult-with-jquery-in-aspnet-mvc/

2) or we can implement a WCF service that also returns JSON How do I return clean JSON from a WCF Service?

Classes used for serialization are different JavaScriptSerializer vs DataContractJsonSerializer and I wonder do they share inside some common core Json serialization code or not, and how they compare in terms of performance and extensibility?

I expect that if you use the same data model, 1st approach seems to be simplier to implement. Are there any other considerations then implementation simplicity comparing JsonResult vs WCF [WebGet(ResponseFormat = WebMessageFormat.Json)] like performance, security, extensibility, scalability, testability etc.?

p.s. I would like to clarify that this question is not about a decision of going with SOA approach or not, how to better separate concerns using architecture layers and so on. Our application already has WCF services to expose some data to 3rd party apps and to isolate the functionality that need to be isolated, so in terms of creating additional projects or hosting infrastructure and configuring WCF services - this all pretty much done already. Suppose the JSON data we want to obtain is not going to be reused somewhere else just for UI controls on a single web page.

Community
  • 1
  • 1
Bogdan_Ch
  • 3,328
  • 4
  • 23
  • 39
  • 1
    I think #1 is perfect for an MVC app, after all, calling a controller and returning JSON is really no different then calling a controller and returning a partial view, or even a whole view. If you need an external app to access your 'action' then a web service would probably be your best option especially as you have it all set up already. – K. Bob Jan 26 '12 at 16:35
  • Not a real question, very broad and too localized. Depends a lot of your applications requirements. – John Farrell Jan 26 '12 at 17:05

1 Answers1

3

If you have a website that is built using MVC and the JSON is used for rendering the page then adding a REST endpoint to do solely this when it would have no other purpose is just adding extra complexity

MVC, as you have said, handles returning JSON from an action quite happily so I would go this route

Richard Blewett
  • 6,089
  • 1
  • 18
  • 23