Метод IEndpointBehavior ApplyClientBehavior не выполняется после добавления поведения в поведение конечной точки - PullRequest
0 голосов
/ 01 мая 2018

Учитывая эти два класса:

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;
    }
}

И этот код инициализации поведения:

var requestInterceptor = new InspectorBehavior();
MYSoapClient.Endpoint.Behaviors.Add(requestInterceptor);

Почему метод ApplyClientBehavior никогда не выполняется и MessageInspector всегда равен нулю?

Не следует ли выполнять ApplyClientBehavior при добавлении поведения в коллекцию поведения конечной точки (я убедился, что это так и переменная requestInterceptor не равна нулю)?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...