[MessageContract] public class CustomerMessage { [MessageHeader] public Guid Id { get; set; } [MessageBodyMember] public String Name { get; set; } [MessageBodyMember] public String Email { get; set; } }
<s:Envelope xmlns:s="[url]http://schemas.xmlsoap.org/soap/envelope/[/url]"> <s:Header> <Action s:mustUnderstand="1" xmlns="[url]http://schemas.microsoft.com/ws/2005/05/addressing/none[/url]"> [url]http://tempuri.org/ICustomerContract/GetCustomerResponse[/url] </Action> <h:Id xmlns:h="[url]http://tempuri.org/[/url]"> 38097c1d-366d-4c58-84a5-93525766630c </h:Id> </s:Header> <s:Body> <CustomerMessage xmlns="[url]http://tempuri.org/[/url]"> <Email>lhj_cauc[@@AT@@]163.com</Email> <Name>TerryLee</Name> </CustomerMessage> </s:Body> </s:Envelope>
public abstract class Message : IDisposable { // 標頭集合 public abstract MessageHeaders Headers { get; } protected bool IsDisposed { get; } public virtual bool IsEmpty { get; } public virtual bool IsFault { get; } // 屬性集合 public abstract MessageProperties Properties { get; } public MessageState State { get; } // 消息版本 public abstract MessageVersion Version { get; } public void Close(); public MessageBuffer CreateBufferedCopy(int maxBufferSize); public static Message CreateMessage(MessageVersion version, string action); // 獲取正文 public T GetBody<T>(); public void WriteBody(XmlWriter writer); public void WriteMessage(XmlWriter writer); public void WriteStartBody(XmlWriter writer); public void WriteStartEnvelope(XmlDictionaryWriter writer); // 更多成員 }
public sealed class EnvelopeVersion { public static EnvelopeVersion None { get; } public static EnvelopeVersion Soap11 { get; } public static EnvelopeVersion Soap12 { get; } }
public sealed class AddressingVersion { public static AddressingVersion None { get; } public static AddressingVersion WSAddressing10 { get; } public static AddressingVersion WSAddressingAugust2004 { get; } }
MessageVersion version = MessageVersion.CreateVersion (EnvelopeVersion.Soap11, AddressingVersion.WSAddressing10);
public sealed class MessageVersion { public static MessageVersion Default { get; } public static MessageVersion None { get; } public static MessageVersion Soap11 { get; } public static MessageVersion Soap11WSAddressing10 { get; } public static MessageVersion Soap11WSAddressingAugust2004 { get; } public static MessageVersion Soap12 { get; } public static MessageVersion Soap12WSAddressing10 { get; } public static MessageVersion Soap12WSAddressingAugust2004 { get; } }
public Message GetCustomer() { Customer customer = new Customer { Id = Guid.NewGuid(), Name = "TerryLee", Email = "lhj_cauc[@@AT@@]163.com" }; Message message = Message.CreateMessage( MessageVersion.Soap11WSAddressing10, "http://localhost/CustomerService/GetCustomer", customer); return message; }
<s:Envelope xmlns:a="[url]http://www.w3.org/2005/08/addressing[/url]" xmlns:s="[url]http://schemas.xmlsoap.org/soap/envelope/[/url]"> <s:Header> <a:Action s:mustUnderstand="1"> [url]http://localhost/CustomerService/GetCustomer[/url] </a:Action> </s:Header> <s:Body> <Customer xmlns:i="[url]http://www.w3.org/2001/XMLSchema-instance[/url]" xmlns="[url]http://schemas.datacontract.org/2004/07/[/url] Data"> <Email>lhj_cauc[@@AT@@]163.com</Email> <Id>d297aa45-2d9e-4f89-aa41-491507db2a21</Id> <Name>TerryLee</Name> </Customer> </s:Body> </s:Envelope>
<s:Envelope xmlns:a="[url]http://schemas.xmlsoap.org/ws/2004/08/addressing[/url]" xmlns:s="[url]http://www.w3.org/2003/05/soap-envelope[/url]"> <s:Header> <a:Action s:mustUnderstand="1"> [url]http://localhost/CustomerService/GetCustomer[/url] </a:Action> </s:Header> <s:Body> <Customer xmlns:i="[url]http://www.w3.org/2001/XMLSchema-instance[/url]" xmlns="[url]http://schemas.datacontract.org/2004/07/[/url] Data"> <Email>lhj_cauc[@@AT@@]163.com</Email> <Id>e13bef92-bba2-47c2-954c-ba7bfe472cc2</Id> <Name>TerryLee</Name> </Customer> </s:Body> </s:Envelope>
<endpoint address="" binding ="basicHttpBinding" contract="TerryLee.MessageHandling.Contract.ICustomerContract" name="defaultBinding"> </endpoint> <endpoint address="Other" binding ="wsHttpBinding" contract="TerryLee.MessageHandling.Contract.ICustomerContract" name="otherBinding"> </endpoint>
foreach (ServiceEndpoint endpoint in host.Description.Endpoints) { Console.WriteLine("Binding:{0}", endpoint.Binding.Name); Console.WriteLine("AddressingVersion:{0}", endpoint.Binding.MessageVersion.Addressing.ToString()); Console.WriteLine("EnvelopeVersion:{0}", endpoint.Binding.MessageVersion.Envelope.ToString()); Console.WriteLine("----------------------------\n"); }
Binding:BasicHttpBinding AddressingVersion:AddressingNone ([url]http://schemas.microsoft.com/ws/2005/05/addres[/url] sing/none) EnvelopeVersion:Soap11 ([url]http://schemas.xmlsoap.org/soap/envelope/[/url]) ---------------------------- Binding:WSHttpBinding AddressingVersion:Addressing10 ([url]http://www.w3.org/2005/08/addressing[/url]) EnvelopeVersion:Soap12 ([url]http://www.w3.org/2003/05/soap-envelope[/url]) ----------------------------
public Message GetCustomer() { Customer customer = new Customer { Name = "TerryLee", Email = "lhj_cauc[@@AT@@]163.com" }; Message message = Message.CreateMessage( MessageVersion.Soap12WSAddressingAugust2004, "http://localhost/CustomerService/GetCustomer", customer); message.Headers.Add(MessageHeader.CreateHeader( "CustomerID", "http://www.cnblogs.com/terrylee", Guid.NewGuid() )); return message; }
<s:Envelope xmlns:a="[url]http://schemas.xmlsoap.org/ws/2004/08/addressing[/url]" xmlns:s="[url]http://www.w3.org/2003/05/soap-envelope[/url]"> <s:Header> <a:Action s:mustUnderstand="1"> [url]http://localhost/CustomerService/GetCustomer[/url] </a:Action> <CustomerID xmlns="[url]http://www.cnblogs.com/terrylee[/url]"> c2f34dd3-d71a-42fa-b3f2-6f58c553c8ee </CustomerID> </s:Header> <s:Body> <Customer xmlns:i="[url]http://www.w3.org/2001/XMLSchema-instance[/url]" xmlns="[url]http://schemas.datacontract.org/2004/07/Data[/url]"> <Email>lhj_cauc[@@AT@@]163.com</Email> <Id>00000000-0000-0000-0000-000000000000</Id> <Name>TerryLee</Name> </Customer> </s:Body> </s:Envelope>
public enum MessageState { Created, Read, Written, Copied, Closed, }
Customer c = new Customer { Name = "TerryLee", Email = "lhj_cauc[@@AT@@]163.com" }; Message message = Message.CreateMessage( MessageVersion.Soap12WSAddressingAugust2004, "http://localhost/CustomerService/GetCustomer", c); Console.WriteLine(message.State); Customer c = message.GetBody<Customer>(); Console.WriteLine(message.State); message.Close(); Console.WriteLine(message.State);
0javascript
收藏css
Ctrl+Enter 發佈html
發佈java
取消jquery