2011-10-03 142 views
1

使用svcutil我从模式文件生成的代码。到目前为止,所有的对象序列化和反序列化确定,除了这种“商品”属性:对象属性不被反序列化

[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; 
     } 
    } 

当我尝试投的项目对象键入查询类型,它实现AbstractQuery我得到一个错误说:

无法以浇注型“System.Xml.XmlElement”对象键入 “OGC.CSW.ebRIMProfile.QueryType”

我试图做到这一点:

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

我不想要XML我想要我的对象,任何想法?

回答

0

我能加入这个额外的行得到它:

前:

[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)] 
+0

什么是 “订单” 吗?你能详细说明它,为什么是2? –

+0

@MathiasLykkegaardLorenzen它设置元素被序列化或反序列化的显式顺序[doc](http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlelementattribute(v = vs。 110)的.aspx) – capdragon

相关问题