Message Contract, Data Contract, XmlSerializer Message XML Body

1.Message Contract Declaration

  [ServiceContract]
    public interface ISocialStatus
    {
        [OperationContract]
        string UpdateStatus(string text);

        [OperationContract]
        void TestContract(Customer cust);
    }

    [MessageContract]
    public class Customer
    {
        [MessageBodyMember]
        public int Id { get; set; }
        [MessageBodyMember]
        public string Name { get; set; }
        [MessageBodyMember]
        public string[] AddressList{get;set;}
    }

XML Format

<s:Body>
<Customer xmlns="http://tempuri.org/">
<AddressList xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<b:string>a</b:string>
<b:string>b</b:string>
</AddressList>
<Id>123</Id>
<Name>Sweep</Name>
</Customer>
</s:Body>

1.1 Message Contract Declaration (with Header)

[ServiceContract]
    public interface ISocialStatus
    {
        [OperationContract]
        string UpdateStatus(string text);

        [OperationContract]
        void TestContract(Customer cust);
    }

    [MessageContract]
    public class Customer
    {
        [MessageHeader]
        public int Id { get; set; }
        [MessageBodyMember]
        public string Name { get; set; }
        [MessageBodyMember]
        public string[] AddressList{get;set;}
    }


XML Format

<s:Header>
<a:Action s:mustUnderstand="1">http://tempuri.org/ISocialStatus/TestContract</a:Action>
<h:Id xmlns:h="http://tempuri.org/">123</h:Id>
<a:MessageID>urn:uuid:aa9a057c-1e6a-42a3-abbf-1045f373379f</a:MessageID>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">http://localhost:12345/GetMessage</a:To>
</s:Header>
<s:Body>
<Customer xmlns="http://tempuri.org/">
<AddressList xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<b:string>a</b:string>
<b:string>b</b:string>
</AddressList>
<Name>Sweep</Name>
</Customer>
</s:Body>


2.Data Contract Declaration

[ServiceContract]
    public interface ISocialStatus
    {
        [OperationContract]
        string UpdateStatus(string text);

        [OperationContract]
        void TestContract(Customer cust);
    }

    [DataContract]
    public class Customer
    {
        [DataMember]
        public int Id { get; set; }
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public string[] AddressList{get;set;}
    }

XML Format

<s:Body>
<TestContract xmlns="http://tempuri.org/">
<cust xmlns:b="http://schemas.datacontract.org/2004/07/Service" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<b:AddressList xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<c:string>a</c:string>
<c:string>b</c:string>
</b:AddressList>
<b:Id>123</b:Id>
<b:Name>Sweep</b:Name>
</cust>
</TestContract>
</s:Body>


3.XmlSerializer Declaration

 [ServiceContract]
    public interface ISocialStatus
    {
        [OperationContract]
        string UpdateStatus(string text);

        [OperationContract]
        void TestContract(Customer cust);
    }

    [XmlSerializerFormat]
    public class Customer
    {
        [XmlAttribute]
        public int Id { get; set; }
        [XmlAttribute]
        public string Name { get; set; }
        [XmlAttribute]
        public string[] AddressList{get;set;}
    }

XML Format

<s:Body>
<TestContract xmlns="http://tempuri.org/">
<cust xmlns:b="http://schemas.datacontract.org/2004/07/Service" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<b:AddressList xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<c:string>a</c:string>
<c:string>b</c:string>
</b:AddressList>
<b:Id>123</b:Id>
<b:Name>Sweep</b:Name>
</cust>
</TestContract>
</s:Body>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值