【问题标题】:object property not being deserialized对象属性未反序列化
【发布时间】:2011-10-03 15:01:30
【问题描述】:

使用 svcutil 我从模式文件生成代码。到目前为止,所有对象都可以序列化和反序列化,除了这个“Item”属性:

    [System.Xml.Serialization.XmlAnyElementAttribute(Order=2)]
    [System.Xml.Serialization.XmlElementAttribute("AbstractQuery", typeof(AbstractQueryType), Order=2)]
    public object Item
    {
        get
        {
            return this.itemField;
        }
        set
        {
            this.itemField = value;
        }
    }

当我尝试将 Item 对象转换为实现 AbstractQuery 的 QueryType 类型时,我收到一条错误消息:

无法将“System.Xml.XmlElement”类型的对象转换为类型 'OGC.CSW.ebRIMProfile.QueryType'

我正在尝试这样做:

(QueryType) test = (QueryType)Request.GetRecords.Item;

我不想要 XML 我想要我的对象,有什么想法吗?

【问题讨论】:

    标签: c# wcf soap xml-serialization


    【解决方案1】:

    我可以通过添加这个额外的行来获得它:

    之前:

    [System.Xml.Serialization.XmlAnyElementAttribute(Order=2)]
    [System.Xml.Serialization.XmlElementAttribute("AbstractQuery", typeof(AbstractQueryType), Order=2)]
    

    之后:

    [System.Xml.Serialization.XmlAnyElementAttribute(Order=2)]
    [System.Xml.Serialization.XmlElementAttribute("AbstractQuery", typeof(AbstractQueryType), Order=2)]
    [System.Xml.Serialization.XmlElementAttribute("Query", typeof(QueryType), Order = 2)]
    

    【讨论】:

    • “订单”有什么作用?你能详细说明一下吗,为什么是2?
    • @MathiasLykkegaardLorenzen 它sets the explicit order in which the elements are serialized or deserialized doc
    猜你喜欢
    • 1970-01-01
    • 2018-12-10
    • 1970-01-01
    • 2014-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多