asp.net - 如何使用 web 服务返回接口(interface)或 "complex"值?

标签 asp.net web-services linked-list

我有一个返回复杂值的网络服务(这是一棵树)

public class DocumentTreeNode
{
    public MyDocument Data
    { get; set;}

    private LinkedList<DocumentTreeNode> _children;

    public IEnumerable<DocumentTreeNode> Children
    {
        get
        {
            return _children.AsEnumerable();
        }
    }

    (...)
}

不幸的是,当我调用网络服务时,它返回
<?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 无法正确序列化我的类(class)(由于 IEnumerable?)。我打算使用 Xml 序列化并让我的服务返回一个 XmlDocument,但我认为这不是最好的方法。

传递这个对象的最简单方法是什么(只需最少的工作)?

最佳答案

序列化程序会跳过返回接口(interface)的属性。它需要一个具体的类型,否则如果不发送额外的类型元数据,就不可能再水合,这不是 OOTB 序列化的一部分。

关于asp.net - 如何使用 web 服务返回接口(interface)或 "complex"值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3575366/

相关文章:

java - 在 Eclipse 中从 WSDL 生成 Web 服务 java 类

c - 计算链表中的元素时出现段错误

c - 一个函数实现,用于剪切链接列表的一部分并将其附加到列表的末尾

c - 为什么我的代码会跳过某些节点?

asp.net - Page_Init 和 Page_Load

jquery - 通过 jQuery 调用 WSDL 服务

asp.net - 从 Excel 电子表格复制并粘贴到 ASP.NET 控件

java - 使用 SAML (SSO) 的 Web 服务安全性 - 如何?

ASP.NET MVC 3 问题(错误?): Different parameter binding priority for GET and POST

c# - 图片不在 Chrome 和 FF 上显示