EndpointAddress类型
EndpointAddress类型有两种功能:它可以方便地保护目标地址的信息,它是一种序列化WS-Addressing终结点到Message中的方式。
EndpointAddress address1 = new EndpointAddress("http://www.andersoft.com/anders");
EndpointAddress address2 = new EndpointAddress(new Uri("http://www.andersoft.com/anders"));
Console.WriteLine(address1.ToString()); //http://www.andersoft.com/anders
Console.WriteLine(address2.ToString()); //http://www.andersoft.com/anders
AddressHeader类型
AddressHeader类型是CLR对于WS-Addressing参数的抽象,它简化了在序列化之前,添加参数到Message的工作,同样也包括反序列化之后获得引用参数的值。
序列化EndpointAddress对象
string urlValue = "http://www.andersoft.com/anders";
AddressHeader addressHeader = AddressHeader.CreateAddressHeader("ref param");
EndpointAddress address = new EndpointAddress(new Uri(urlValue), addressHeader);
Message message = Message.CreateMessage(MessageVersion.Soap12WSAddressingAugust2004, "SomeAction");
message.Headers.FaultTo = address;
//<s:Envelope xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:s="
//http://www.w3.org/2003/05/soap-envelope">
// <s:Header>
// <a:Action s:mustUnderstand="1">SomeAction</a:Action>
// <a:FaultTo>
// <a:Address>http://www.andersoft.com/anders</a:Address>
// <a:ReferenceParameters>
// <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">ref
//param</string>
// </a:ReferenceParameters>
// </a:FaultTo>
// </s:Header>
// <s:Body />
//</s:Envelope>
可以用EndpointAddress的ApplyTo方法把EndpointAddress的值赋给Message。
string urlValue = "http://www.andersoft.com/anders";
AddressHeader addressHeader = AddressHeader.CreateAddressHeader("ref param");
EndpointAddress address = new EndpointAddress(new Uri(urlValue), addressHeader);
Message message = Message.CreateMessage(MessageVersion.Soap12WSAddressingAugust2004, "SomeAction");
address.ApplyTo(message);
//<s:Envelope xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:s="
//http://www.w3.org/2003/05/soap-envelope">
// <s:Header>
// <a:Action s:mustUnderstand="1">SomeAction</a:Action>
// <a:To s:mustUnderstand="1">http://www.andersoft.com/anders</a:To>
// <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">ref para
//m</string>
// </s:Header>
// <s:Body />
//</s:Envelope>
复制消息
Message.CreateBufferedCopy为消息实例创建一个缓存模式的消息拷贝。
Message message = Message.CreateMessage(MessageVersion.Soap12WSAddressingAugust2004, "SomeAction");
Console.WriteLine(message.State.ToString()); //Created
MessageBuffer messageBuffer = message.CreateBufferedCopy(Int32.MaxValue); //Copied
Console.WriteLine(message.State.ToString());
Message newMessage = messageBuffer.CreateMessage();
Console.WriteLine(newMessage.State.ToString()); //Created