2017-09-01 87 views
0

我寫了一個WCF服務。下面是我的代碼。WCF服務XML序列化

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

如何獲得我所期望的響應。請人幫我

回答

0

嘗試:

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

快樂碼!