.net C# WebChannelFactory keepAliveEnabled=false с webHttpBehavior

Я создаю WebChannelFactory. Мне нужно установить KeepAlive=false. Я нашел только одно решение использовать CustomBinding. и установите для свойства keepAliveEnabled значение false.

Я также использую нестандартное поведение для своей фабрики.

Код:

static CustomBinding GetBinding(MySettings serviceSettings = null)
    {
        var customBinding = new CustomBinding();
        HttpTransportBindingElement transportBindingElement = new HttpTransportBindingElement();
        transportBindingElement.KeepAliveEnabled = false;
        transportBindingElement.MaxBufferSize = 0x07000000;
        transportBindingElement.MaxReceivedMessageSize = 0x07000000;

        if (serviceSettings != null)
        {
            customBinding.SendTimeout = serviceSettings.SendTimeout;
        }

        customBinding.Elements.Add(transportBindingElement);

        return customBinding;
    }

    var customBinding = GetBinding(serviceSettings);
        WebChannelFactory<TChannel> factory = new WebChannelFactory<TChannel>(customBinding, new Uri(url));
        factory.Endpoint.Behaviors.Add(new MyWebHttpBehavior(userId));

 class MyWebHttpBehavior : IEndpointBehavior
{
    private int _userId;

    public MyWebHttpBehavior(int userId)
    {
        _userId = userId;
    }

    public void AddBindingParameters(ServiceEndpoint serviceEndpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)

    { }

    public void ApplyClientBehavior(ServiceEndpoint serviceEndpoint, System.ServiceModel.Dispatcher.ClientRuntime behavior)
    {
        behavior.MessageInspectors.Add(new MyClientMessageInspector(_userId));
    }

    public void ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
    { }

    public void Validate(ServiceEndpoint serviceEndpoint)
    { }
}

В текущей ситуации я получаю ошибку "нет привязки с None MessageVersion".

0 ответов

Другие вопросы по тегам