2017-08-29 40 views
0

與我以前的帖子變化的響應消息的XML格式在WCF

Getting the response result as an array and not a object in web service

我寫了一個Web服務,該服務的響應消息如下

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

我需要改變的反應如下

s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
     <s:Header /> 
     <s:Body> 
     <signOnResponse xmlns="http://tempuri.org/"> 
      <signOnResult>NA</signOnResult> 
      <signOnResult>NA</signOnResult> 
      <signOnResult>NA</signOnResult> 
      <signOnResult>10</signOnResult> 
     </signOnResponse> 
     </s:Body> 
    </s:Envelope> 

網站m我寫的方法返回字符串數組。

爲了得到我對首選結構的響應,我正在做一個研究,我是否可以改變XML序列化的格式來給出響應。但我找不到合適的解決方案。我也嘗試過實施IClientMessageInspector

注意:用php編寫的客戶端可以讀取不在字符串對象下的XML結構。它只能讀取下面的XML。並且不能對客戶端代碼進行更改。

s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
      <s:Header /> 
      <s:Body> 
     <signOnResponse xmlns="http://tempuri.org/"> 
      <signOnResult>NA</signOnResult> 
      <signOnResult>NA</signOnResult> 
      <signOnResult>NA</signOnResult> 
      <signOnResult>10</signOnResult> 
     </signOnResponse> 
     </s:Body> 
    </s:Envelope> 

在此先感謝

回答

0

什麼是您的響應類是什麼樣子?

試試這個:

[XmlRoot(ElementName="signOnResponse", Namespace="http://tempuri.org/")] 
public class SignOnResponse { 
    [XmlElement(ElementName="signOnResult", Namespace="http://tempuri.org/")] 
    public List<string> SignOnResult { get; set; } 
    [XmlAttribute(AttributeName="xmlns")] 
    public string Xmlns { get; set; } 
} 
+0

請看看我以前的帖子。所以你可以得到一個清晰的圖像。我已經在WCF 中完成了https://stackoverflow.com/questions/45921434/getting-the-response-result-as-an-array-and-not-a-object-in-web-service?noredirect= 1#comment78802753_45921434 – vithushan

+0

請看我以前的帖子。所以你可以得到一個清晰的圖像。我已經在WCF [鏈接](https://stackoverflow.com/questions/45921434/getting-the-response-result-as-an-array-and-not-a-object-in-web-服務?noredirect = 1#comment78802753_45921434) – vithushan