【问题标题】:how to get Soap Envelope attribute value in wcf service如何在 wcf 服务中获取 Soap Envelope 属性值
【发布时间】:2016-03-05 11:43:12
【问题描述】:

如何在 wcf 服务中获取 SOAP xml 属性值?

  <ns3:NotifRQ Status="Commit" 
               xmlns:ns2="http://www.dddd.com/df/dd/" 
               xmlns:ns3="http://www.dd.org/OTA/">

      <ns3:rev>dfdfkkl</ns3:rev>
      <ns3:change>dfdfkkl</ns3:change>
  </ns3:NotifRQ>

这是我现在拥有的数据合约代码:

[DataContract(Name = "NotifRQ", Namespace = "http://www.dd.org/OTA/")]
public class NotifRQ
{
    [DataMember(Name = "Status")]
    public string ResStatus;
}

【问题讨论】:

  • 你能简单解释一下吗?你想得到什么?或者你到底想说什么?
  • 我需要在 wcf 中超越 SOAP XML () 属性“状态”值
  • 如何在 wcf 的上述属性中创建类
  • 我问了 SOAP Xml @rene

标签: c# wcf object


【解决方案1】:

您的Status 属性必须是NotifRQ 类的字段或属性,并且您需要指示WCF 使用不太理想的XmlSerializer 而不是DatacontractSerializer,如here 所述。你可以通过在你的类上使用XmlSerializerFormat 属性来实现。

您现在可以将XmlAttribute 应用于类的字段或属性,以获取或设置 xml 元素的属性值。

按如下方式创建和注释您的类:

[DataContract(Namespace="http://www.dd.org/OTA/")]
[XmlSerializerFormat]
public class NotifRQ 
{

   [DataMember, XmlAttribute] 
   public string Status="Commit";

   [DataMember]
   public string  rev;

   [DataMember]
   public string  change;
}

以上类将写入和读取以下线格式:

<?xml version="1.0" encoding="utf-16"?>
<NotifRQ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
         Status="Commit">
  <rev>foo</rev>
</NotifRQ>

【讨论】:

    猜你喜欢
    • 2019-05-29
    • 2015-03-24
    • 2012-03-18
    • 2020-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-05
    • 1970-01-01
    相关资源
    最近更新 更多