将 ASMX Web 服务的响应读回磁盘中的对象
我们有一个 ASP.Net Web 服务,它将 XML 文件接收到 PDA 并将其映射到对象(标准 .Net Web 方法)。是否有一种简单的方法可以在将此 XML 响应保存到磁盘后,将其读回到之前的相同对象结构中?
PDA 应用程序在接收到从 Web 服务返回的数据后会自动执行此操作,但找不到一种方法可以让我提供流等以“离线”重复该过程。
We have an ASP.Net web service which receives an XML file to a PDA and maps it to objects (a standard .Net web method). Is there an easy method of after saving this XML response to disk, having it read back into the same object structure it was in before?
The PDA application automatically does this after receiving the data back from the web service but couldn't find a method that would let me supply a stream or the like to repeat the process 'offline'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
序列化允许您执行此操作 - 这实际上是通过 Web 服务发送对象的方式。
如果你幸运的话,下面的代码将序列化一个对象(称为“object_type”类型的“object”。)
并反序列化:
我说“如果你幸运的话”,因为 90% 的时间对我有用。如果类中的属性是抽象类,则可能需要在 XmlSerializer 构造函数中声明扩展该抽象类的所有类类型。还要注意类内没有“循环依赖”。
Serialization allows you to do this - it's actually how objects are sent across a web-service.
If you're lucky, the following code will serialise an object (called "object" of type "object_type".)
And to de-serialise:
I say "if you're lucky" because 90% of the time that works for me. If you have properties within the class that are abstract classes you may need to declare all class types that extend that abstract class in the
XmlSerializer
constructor. Also be careful there are no "circular dependencies" within the class.