WCF wsHttpBinding with http keepalive

后端 未结 2 2097
攒了一身酷
攒了一身酷 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 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();
    transportElement.KeepAliveEnabled = false;
    
    proxy.Endpoint.Binding = customBinding;
    

提交回复
热议问题