Greetings,
I need to add a custom header to my service endpoint. I saw the api call to add a custom header (
AddCustomHeader) to the service connection, however, it seems to require that the value be the same
for the life of the connection. Is there a way (similar to adding a wcf behavior) to change the value
per call as opposed to keeping the same value for the life of the connection?
Client<T> svc = new Client<T>();
svc.AddCustomHeader("name", "namespace", "value");
Alternatively, I tried using the address from the neuron discovered client connector to construct a channel
using the ChannelFactory and adding a custom behavior, but the headers seem to be stripped and not
passed on to the service connector.
scf = new ChannelFactory<T>(new WSHttpBinding(SecurityMode.None, false), svc.Address);
scf.Endpoint.Behaviors.Add(new OriginationIdBehavior());
serviceConnection = scf.CreateChannel();
Client<T> svc = new Client<T>();
Everything works if I don't use the bus to transport the message to the service address, but using Neuron,
the headers are removed.
Thanks for your help,
Dave
Tags:
Hi Dave,
you just have to make sure that you check the "Capture custom headers" check box on the Client Connector, and then check the "Restore custom headers" checkbox on the service connectors. That way custom headers will flow through the bus without issue.
Kind regards,
Marty
Think I found it.
On the Client Connector: Capture Custom Headers
On the Service Connector: Restore Custom Headers
:)
Hi Dave,
Also, I'm not sure if the AddCustomHeader() method will work for you even if you enable the custom headers. However, this will work:
public
{
{
static void ClientTSendRequestByServiceNameAddHeaders()XmlReader xmlReader = null;Message reqMsg = null;using (Client/font>IRequestChannel> client = new Client/font>IRequestChannel>("PublicHRService"))// get the custom soap header
System.Xml.
{
{
XmlDocument doc = GetCustomSoapHeader();using (xmlReader = CreateMessage(_msg))using (reqMsg = Message.CreateMessage(MessageVersion.Default, "V2", xmlReader))// add custom headers to define services for scatter gather patter
reqMsg.Headers.Add(header);
reqMsg.Close();
}
xmlReader.Close();
}
}
}
MessageHeader header = MessageHeader.CreateHeader(_propName, _ns, doc.OuterXml);Console.WriteLine(client.Proxy.Request(reqMsg).ToString()); Hi Dave,
Also, I'm not sure if the AddCustomHeader() method will work for you even if you enable the custom headers. However, this will work:
public static void ClientTSendRequestByServiceNameAddHeaders()
{
XmlReader xmlReader = null;
Message reqMsg = null;
using (Client<IRequestChannel> client = new Client<IRequestChannel>("PublicHRService"))
{
// get the custom soap header
System.Xml.XmlDocument doc = GetCustomSoapHeader();
using (xmlReader = CreateMessage(_msg))
{
using (reqMsg = Message.CreateMessage(MessageVersion.Default, "V2", xmlReader))
{
// add custom headers to define services for scatter gather patter
MessageHeader header = MessageHeader.CreateHeader(_propName, _ns, doc.OuterXml);
reqMsg.Headers.Add(header);
Console.WriteLine(client.Proxy.Request(reqMsg).ToString());
reqMsg.Close();
}
xmlReader.Close();
}
}
}
Hi Dave,
Also, I'm not sure if the AddCustomHeader() method will work for you even if you enable the custom headers. However, this will work:
public static void ClientTSendRequestByServiceNameAddHeaders()
{
XmlReader xmlReader = null;
Message reqMsg = null;
using (Client<IRequestChannel> client = new Client<IRequestChannel>("PublicHRService"))
{
// get the custom soap header
System.Xml.XmlDocument doc = GetCustomSoapHeader();
using (xmlReader = CreateMessage(_msg))
{
using (reqMsg = Message.CreateMessage(MessageVersion.Default, "V2", xmlReader))
{
// add custom headers to define services for scatter gather patter
MessageHeader header = MessageHeader.CreateHeader(_propName, _ns, doc.OuterXml);
reqMsg.Headers.Add(header);
Console.WriteLine(client.Proxy.Request(reqMsg).ToString());
reqMsg.Close();
}
xmlReader.Close();
}
}
}
Neuron ESB Product Support Forums and Communities
© 2024 Created by Neuron Admin. Powered by