0

I have to build small MVC3 ASP.NET based portal that will receive data in JSON form from other also MVC3 ASP.NET based web service. Service will get data from database, serialize it, and send it as JsonResult. Portal needs to capture that data and deserialize it back to model and toss it to the appropriate view.

As I'm kinda new to this, I was thinking to use WebClient for web portal, but I don't know if there is something better than that? Idea is to process data within controller.

Also, I would appreciate any examples/tutorials.

Thanks

Admir Tuzović
  • 10,997
  • 7
  • 35
  • 71

2 Answers2

2

I have literally just done this. I created a generic class to consume external web services using the HttpWebRequest and HttpWebResponse class's.

Arguements for using the HttpWebRequest class could be that I believe you get more granular control when using HttpWebRequest, as the WebClient class is essentially a wrapper for the HttpWebRequest. And then de-serialize the Web Service responses into custom objects in your Web Portal App.

I would also not process the data in the controller and keep them cleaner, i abstracted this task to a Service class where any validation / modifications needed to be done on the responses.

gdp
  • 8,032
  • 10
  • 42
  • 63
0

I'm not sure I understood your question completely, but if you're asking about the proper way of communication between two web applications, I would suggest that you would use WCF. In this case, communication will be done through SOAP messages and not JSON.

But if you are asking about how to serialize an object into JSON format, then you can use JSON.NET library.

1. Introduction to WCF

2. JSON.NET

3. Helpful resource

Community
  • 1
  • 1
Kassem
  • 8,116
  • 17
  • 75
  • 116
  • Sorry, but my question was clear enough. I have web services that takes request / sends response as JSON so using WCF and SOAP is not what I'm looking for. I know how to serialize/deserialize JSON without 3rd party frameworks. I'm looking the best method to consume that web service within MVC3 controller. Thanks for the effort though. – Admir Tuzović May 12 '12 at 10:11
  • @BarisaPuter I would update your question to reflect "Im looking for the suitable method to consume a web service" then. As i didnt fully understand your question either. – gdp May 12 '12 at 11:11