簡體   English   中英

WCF服務XML序列化

[英]WCF Service XML Serialization

我寫了WCF服務。 下面是我的代碼。

 [XmlArrayItem(ElementName="GetResult ")]
 public List<string> Array = new List<string>();

 public List<string> Get()
    {
        this.Array.Add("Apple");
        this.Array.Add("Orange");
        this.Array.Add("Pears");
        return this.Array;
    }

我需要XML響應是這樣的

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header />
  <s:Body>
    <GetResponse xmlns="http://tempuri.org/">
      <GetResult xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <GetResult >Apple</GetResult >
        <GetResult >Orange</GetResult >
        <GetResult >Pears</GetResult >
      </GetResult>
    </GetResponse>

但是實際結果是

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header />
  <s:Body>
    <GetResponse xmlns="http://tempuri.org/">
      <GetResult xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:string>Apple</a:string>
        <a:string>Orange</a:string>
        <a:string>Pears</a:string>
      </GetResult>
    </GetResponse>

如何獲得我想要的回應。 請有人幫我

嘗試:

[XmlArrayItem(ElementName="")] 
public List<string> GetResult = new List<string>();

快樂代碼!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM