如何返回一个接口或一个“复杂”的接口使用网络服务的价值?
我有一个返回复杂值的Web服务(这是一棵树)
public class DocumentTreeNode
{
public MyDocument Data
{ get; set;}
private LinkedList<DocumentTreeNode> _children;
public IEnumerable<DocumentTreeNode> Children
{
get
{
return _children.AsEnumerable();
}
}
(...)
}
不幸的是,当我调用Web服务时,它返回
<?xml version="1.0" encoding="utf-8"?>
<DocumentTreeNode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://tempuri.org/" />
我已经仔细检查过,并且我应该返回的对象不为空。
我猜这意味着 ASP.Net 无法正确序列化我的类(由于 IEnumerable?)。我打算使用 Xml 序列化并让我的服务返回 XmlDocument,但我认为这不是最好的方法。
传递该对象的最简单方法是什么(只需最少的工作)?
I have a webservice that returns a complex value (this is a tree)
public class DocumentTreeNode
{
public MyDocument Data
{ get; set;}
private LinkedList<DocumentTreeNode> _children;
public IEnumerable<DocumentTreeNode> Children
{
get
{
return _children.AsEnumerable();
}
}
(...)
}
Unfortunately, when I call the webservice, it returns
<?xml version="1.0" encoding="utf-8"?>
<DocumentTreeNode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://tempuri.org/" />
I have double checked, and the object I am supposed to return is not empty.
I'm guessing that means ASP.Net is unable to properly serialize my class (due to the IEnumerable?). I was going to use an Xml Serialization and have my service return an XmlDocument, but I don't think this is the best way.
What is the easiest way to pass this object through (with minimal work) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
返回接口的属性会被序列化器跳过。它需要一个具体的类型,否则如果没有发送额外的类型元数据(这不是 OOTB 序列化的一部分),重新水合就不可能。
Properties that return interfaces are skipped by the serializer. It requires a concrete type, otherwise re-hydration would be impossible without additional type metadata sent along, which is not part of the OOTB serialization.