2012-12-28 28 views
0

我在序列化的XML元素,特別是去除根標籤數組有問題/收集如何收集刪除根元素時WCF序列化集合屬性

public Class Part 
    { 
     public Guid Id { get; set; } 
     [System.Xml.Serialization.XmlElementAttribute(IsNullable = false)] 
     [DataMember(IsRequired = true)] 
     public string PartNumber { get; set; } 

     [System.Xml.Serialization.XmlElementAttribute(IsNullable = false)] 
     [DataMember(IsRequired = true)] 
     public string PartName { get; set; } 

     [System.Xml.Serialization.XmlElementAttribute(IsNullable = true)] 
     public string Description { get; set; } 

     [System.Xml.Serialization.XmlElementAttribute(IsNullable = false)] 
     public DateTime LastUpdated { get; set; } 

     [XmlElement()] 
     public string[] PartDetails{ get; set; } 
    } 

WCF序列化到這個

<b:Part> 
      <b:PartDetail xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> 
       <c:string>ABC</c:string> 
      </b:PartDetail> 
      <b:PartDetail xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> 
       <c:string>DEF</c:string> 
      </b:PartDetail> 
      <b:Description> JGHGS SGHSGH SJGHSJG</b:Description> 
      <b:Id>740ead2d-84e8-4da0-9115-28dea5f0bd28</b:Id> 
      <b:LastUpdated>2012-11-30</b:LastUpdated> 
      <b:PartName>AAA BBB CCC DDDD</b:PartName> 
      <b:PartNumber>1</b:PartNumber> 
      </b:Part> 

我需要的東西

<b:Part> 
       <b:PartDetail xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/Arrays">ABC</b:PartDetail> 
       <b:PartDetail xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/Arrays">DEF</b:PartDetail>    

       <b:Description> JGHGS SGHSGH SJGHSJG</b:Description> 
       <b:Id>740ead2d-84e8-4da0-9115-28dea5f0bd28</b:Id> 
       <b:LastUpdated>2012-11-30</b:LastUpdated> 
       <b:PartName>AAA BBB CCC DDDD</b:PartName> 
       <b:PartNumber>1</b:PartNumber> 
       </b:Part> 

我在SO中發現了類似的問題,沒有得到任何明確的答案(可能不明白)如何使用它與WCF。

基本上我想要的

<ArrayPropertyName>ABC</ArrayPropertyName> 
<ArrayPropertyName>DEF</ArrayPropertyName> 
<ArrayPropertyName>GHI</ArrayPropertyName> 

代替

<ArrayPropertyName> 
<string> ABC</string> 
<string> DEF</string> 
<string> GHI</string> 
</ArrayPropertyName> 

是它可以搜索和WCF之前發送XML序列化的數據刪除標記出來?

讓我知道問題是否清楚。

回答

0

你需要創建一個PartDetail類來實現這一點,像

public class PartDetail 
{ 
    [XmlText()] 
    public string value; 
}  

public Class Part 
{ 

    [XmlElement("PartDetail")] 
    public PartDetail[] PartDetails { get; set; } 

}