I'm trying to add a custom header to a wcf client hitting a standard, RESTful endpoint. I am trying to add some kind of header that will just allow me to trace requests from one layer to the next. Here's how I've tried to implement it:
public class DynatracePurePathHeaderAppender : IClientMessageInspector, IEndpointBehavior
{
object IClientMessageInspector.BeforeSendRequest(ref Message request, IClientChannel channel)
{
var dynaHeader = MessageHeader.CreateHeader("Action", "ns.yellowbook.jeff", "dynatrace",false);
request.Headers.Add(dynaHeader);
return null;
}
void IClientMessageInspector.AfterReceiveReply(ref Message reply, object correlationState)
{
return;
}
public void Validate(ServiceEndpoint endpoint){}
public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters){}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher){}
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
clientRuntime.MessageInspectors.Add(this);
}
}
public class DynatracePurePathHeaderAppenderElement : BehaviorExtensionElement
{
protected override object CreateBehavior()
{
return new DynatracePurePathHeaderAppender();
}
public override Type BehaviorType
{
get { return typeof(DynatracePurePathHeaderAppender); }
}
}
I then configure the client successfully, but when this runs, I get the following exception: System.InvalidOperationException: Envelope Version 'EnvelopeNone (http://schemas.microsoft.com/ws/2005/05/envelope/none)' does not support adding Message Headers.
Anyone have any suggestions on how to insert this little barium meal?