属性c#的SOAP XMl序列化

时间:2019-04-03 18:37:53

标签: xml serialization soap

目前我的肥皂是这样生成的

 <HdrFault>
     <Fault>   
        <ConsumerProd>
           <Value>soa test</Value>
        </ConsumerProd>
     <Fault>
 </HrdFault>

我希望它像这样生成

<HdrFault>
   <Fault>   
      <ConsumerProd>soa test</ConsumerProd>
   <Fault>
</HrdFault>

这是业务对象。我了解为什么它在那里有一个“值”字段。如何将其序列化为具有上述Soap XML?

[MessageContract]
public partial class HdrFault
{

    private FaultHdr_CType faultHdrField;

    [MessageBodyMember]
    public FaultHdr_CType FaultHdr
    {
        get
        {
            return this.faultHdrField;
        }
        set
        {
            this.faultHdrField = value;
        }
    }
}

[MessageContract]
public class FaultHdr_CType
{
    #region ConsumerProd

    [MessageBodyMember]
    public FaultConsumerProd_Type ConsumerProd { get; set; }

    #endregion
}

[MessageContract]
public class FaultConsumerProd_Type
{
    #region Value

    [MessageBodyMember]
    public string Value { get; set; }

    #endregion
}

1 个答案:

答案 0 :(得分:0)

我做了两件事来解决该问题。 添加[XmlText]

  [MessageContract]
    public class ValidConsmName_Type
    {

        #region Value

         [XmlText]
        [MessageBodyMember]
        public string Value { get; set; }

        #endregion
    }

第二,我在合同中添加了以下内容

[XmlSerializerFormat(SupportFaults = true)]  
    [ServiceContract(Namespace = "http://jackhenry.com/jxchange/TPG/2008")]
    public interface IInt
{
..}