【问题标题】:Change the XML Format of the Response message in wCF在 wCF 中更改响应消息的 XML 格式
【发布时间】:2017-08-29 11:13:59
【问题描述】:

与我之前的帖子有关

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>

我编写的 web 方法返回字符串数组。

为了获得对我首选结构的响应,我正在研究是否可以更改 XML 序列化的格式以给出响应。但我找不到合适的解决方案。我也尝试实现 IClientMessageInspector

注意:用php编写的客户端可以读取不在string对象下的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>

提前致谢

【问题讨论】:

    标签: c# xml web-services wcf


    【解决方案1】:

    你的响应类是什么样的?

    试试这个:

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

    【讨论】:

    • 请看我之前的帖子。所以你可以得到一个清晰的图像。我已经在 WCF stackoverflow.com/questions/45921434/… 中完成了
    • 请看我之前的帖子。所以你可以得到一个清晰的图像。我已经在 WCF link
    猜你喜欢
    • 1970-01-01
    • 2023-03-10
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 2020-11-18
    • 1970-01-01
    • 2013-10-19
    • 1970-01-01
    相关资源
    最近更新 更多