简体   繁体   中英

Object mapping in MVC3 application using REST web service API

I'm trying to consume a RESTful web service API and use the data returned to construct an MVC3 site.

I'm not sure how best to proceed when handling the returned data. Should I manually create classes for the return data or is there a simpler/safer way?

Can anyone point me in the direction of a good tutorial?

Edit

To add some background info...

I might make a call to the API for some region information. This could result in a collection of depots being returned. Drilling down into the data, I could then request the routes associated with a depot and then request the drivers associated with the depot.

In the example above, I'll need to create objects for a region, depot and driver.

Is there a cleaver way to do this (maybe from the WSDL) or is it a typing exercise making properties for each object.

I suppose I could do with something like the entity framework to model the objects without having the database exposed to me. does such a thing exist?

If your rest service is returning an XML , you may load that to an XMLDocument /XDocument and parse thru it to get the relevant details. You can do LINQ TO XML too on this to make things easier.

If it is returning JSON , You can use WebClient.DownloadString method to get the data in string format and then Deserialize that to your entities. in that case, you need those fake / proxy classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM