I need to add the HTTP header for each message in WCF Routing service before sending to back end service. I have implemented the below class. However when I debug "BeforeSendRequest " is not called hence HTTP header ic not added.
I noticed that "AfterReceiveRequest" is called and I added HTTP header but this is found that header is not sending to back ence server.
I need to add when "BeforeSendRequest " is called however , this is not triggering.
public class RouterMessageLogger : BehaviorExtensionElement, IClientMessageInspector, IEndpointBehavior, IDispatchMessageInspector
{
public override Type BehaviorType
{
get
{
return typeof(RouterMessageLogger);
}
}
protected ove开发者_Python百科rride object CreateBehavior()
{
return new RouterMessageLogger();
}
#region IClientMessageInspector Members
**public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
Message MyMsg = request;
this.AddHTTPHeader(ref request);
//_Logging.LogMessage("Routing message to service");
return null;
}**
public void AfterReceiveReply(ref Message reply, object correlationState)
{
Message MyMsg = reply;
//_Logging.LogMessage("Response from service received");
}
#endregion
#region IDispatchMessageInspector Members
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
Message MyMsg = request;
this.AddHTTPHeader( ref request);
//_Logging.LogMessage("Message received from client");
return request;
}
public void BeforeSendReply(ref Message reply, object correlationState)
{
Message MyMsg = reply;
this.AddHTTPHeader(ref reply);
//_Logging.LogMessage("Sending response to client");
}
#endregion
#region IEndpointBehavior Members
public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
{
bindingParameters.Add(this);
//return;
}
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
clientRuntime.MessageInspectors.Add(this);
clientRuntime.CallbackDispatchRuntime.ImpersonateCallerForAllOperations = true;
}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
endpointDispatcher.DispatchRuntime.MessageInspectors.Add(this);
}
public void Validate(ServiceEndpoint endpoint)
{
return;
}
}
The issue is solved with below solution.
Disable the SOAPProcessingBehavior for the service or the endpoint you are routing to (in your routing config). This link tels you how to do it: http://msdn.microsoft.com/en-us/library/ee816919.aspx
精彩评论