Bogdan_Ch
Bogdan_Ch

Reputation: 3336

Pros and cons requesting JSON data from MVC Controller vs WCF service

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.

Upvotes: 1

Views: 1526

Answers (1)

Richard Blewett
Richard Blewett

Reputation: 6109

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

Upvotes: 3

Related Questions