WCF wsHttpBinding with http keepalive

后端 未结 2 2095
攒了一身酷
攒了一身酷 2020-12-05 20:05

I have a WCF client which uses a wsHttpBinding, I would like to enable http keep-alive.

I\'m hoping I can turn this on by just changing the client config... I\'ve fo

相关标签:
2条回答
  • 2020-12-05 20:47

    Keep alive is enabled by default on all HTTP based bindings and it is not possible to turn it off. If you want to turn it off you must create whole new custom binding and set keepAliveEnabled to false on httpTransport binding element.

    0 讨论(0)
  • 2020-12-05 21:11

    You'll have to use a custom binding in order to disable the Keep-Alive header, since that feature is not exposed in any of the built-in binding classes.

    The easiest way to achieve this without having to define a custom binding from scratch, is to customize the existing BasicHttpBinding or WSHttpBinding instance associated to the client proxy in code.

    Here's an example:

    var proxy = new MyServiceClient();
    var customBinding = new CustomBinding(proxy.Endpoint.Binding);
    var transportElement = customBinding.Elements.Find<HttpTransportBindingElement>();
    transportElement.KeepAliveEnabled = false;
    
    proxy.Endpoint.Binding = customBinding;
    
    0 讨论(0)
提交回复
热议问题