Given these two classes:
public class InspectorBehavior : IEndpointBehavior
{
public MessageInspector MessageInspector;
public void AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters){}
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher){}
public void Validate(ServiceEndpoint endpoint){}
public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
MessageInspector = new MessageInspector();
clientRuntime.MessageInspectors.Add(MessageInspector);
}
}
public class MessageInspector : IClientMessageInspector
{
public string LastRequestXML { get; private set; }
public string LastResponseXML { get; private set; }
public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
LastResponseXML = reply.ToString();
}
public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
{
LastRequestXML = request.ToString();
return request;
}
}
And this behavior initialization code:
var requestInterceptor = new InspectorBehavior();
MYSoapClient.Endpoint.Behaviors.Add(requestInterceptor);
Why is it that ApplyClientBehavior
method is never executed and MessageInspector
is always null?
Shouldn't ApplyClientBehavior
be executed when the behavior is added to Endpoint Behavior collection (I verified that it was and that requestInterceptor variable is not null) ?