变化的响应消息的XML格式在WCF

问题描述:

与我以前的帖子变化的响应消息的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> 

在此先感谢

什么是您的响应类是什么样子?

试试这个:

[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://*.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://*.com/questions/45921434/getting-the-response-result-as-an-array-and-not-a-object-in-web-服务?noredirect = 1#comment78802753_45921434) – vithushan