简体   繁体   English

使用REST Web服务API的MVC3应用程序中的对象映射

[英]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. 我正在尝试使用RESTful Web服务API,并使用返回的数据来构建MVC3网站。

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. 我可能会调用API以获得一些区域信息。 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. 是否有一个切肉刀方法(也许来自WSDL)来做到这一点,或者是为每个对象设置属性的打字练习。

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. 如果您的其余服务返回XML ,则可以将其加载到XMLDocument / XDocument并进行解析以获取相关详细信息。 You can do LINQ TO XML too on this to make things easier. 您也可以对此执行LINQ TO XML ,以使事情变得更容易。

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. 如果返回JSON ,则可以使用WebClient.DownloadString方法获取字符串格式的数据,然后将其反序列化为您的实体。 in that case, you need those fake / proxy classes. 在这种情况下,您需要那些伪造的/代理类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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