-
Notifications
You must be signed in to change notification settings - Fork 22
Custom SOAP Headers
For this example, I'll show you how to read/write the WS-Addressing headers in a received message from the WCF connectors. First, to access the SOAP headers from a message received from a WcfServerConnector, you can simply access the Headers property on the WcfReceiveResult. The following code is written in the MessageAvailable event handler for a WcfServerConnector:
static void conn_MessageAvailable(object sender, MARC.Everest.Connectors.UnsolicitedDataEventArgs e)
{
// Get the sending connector that raised the event
var connector = sender as WcfServerConnector;
if (connector == null)
throw new ArgumentException("Must be called from a WcfServerConnector", "sender");
// Receive the message
var receiveResult = connector.Receive() as WcfReceiveResult;
Pretty standard Everest stuff, next we'll emit the value of the WS-Addressing headers:
if (receiveResult.Headers != null){
Console.WriteLine(receiveResult.Headers.To);
Console.WriteLine(receiveResult.Headers.Action);
}
We can access the Headers array just like any other WCF Header, this applies to constructing the response as well. To construct the response, populate the ResponseHeaders on the receiveResult prior to call "Send()" on the server connector.
receiveResult.ResponseHeaders = new System.ServiceModel.Channels.MessageHeaders
(receiveResult.Headers.MessageVersion);
receiveResult.ResponseHeaders.Add(MessageHeader.CreateHeader("myHeader", "urn:my-ns:com", "Value"));
connector.Send(new MCCI_IN000002CA(), receiveResult);
This code will return the following soap header:
< tns:myHeader xmlns:tns="urn:my-ns:com">Value</tns:myHeader>
More complex headers can be added the same way you would add standard System.ServiceModel.Channel.MessageHeader objects. It is also possible to send message headers using the overridden Send() method on the WcfClientConnector:
var conn = new WcfClientConnector();
// trimmed
MessageHeaders messageHeaders = new System.ServiceModel.Channels.MessageHeaders(MessageVersion.Soap12);messageHeaders.Add(MessageHeader.CreateHeader("myHeader", "urn:my-ns:com", "Value"));
conn.Send(instance, messageHeaders);