Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF wsHttpBinding with http keepalive

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 found plenty of descriptions of how to turn on keep-alives for a basicHttp binding, but no luck with wsHttpBinding... is this possible?

Many thanks.

Here's my client binding:

  <wsHttpBinding>
    <binding name="WSHttpBinding_IRepositoryService" closeTimeout="00:00:10"
      openTimeout="00:00:10" receiveTimeout="00:05:00" sendTimeout="00:05:00"
      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
      maxBufferPoolSize="524288" maxReceivedMessageSize="655360" messageEncoding="Mtom"
      textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="81920" maxArrayLength="163840"
        maxBytesPerRead="409600" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
        enabled="true" />
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None"
          realm="">
          <extendedProtectionPolicy policyEnforcement="Never" />
        </transport>
        <message clientCredentialType="Windows" negotiateServiceCredential="true"
          algorithmSuite="Default" establishSecurityContext="true" />
      </security>

    </binding>
</wsHttpBinding>
like image 304
Nathan Avatar asked Jun 30 '11 12:06

Nathan


2 Answers

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;
like image 146
Enrico Campidoglio Avatar answered Oct 13 '22 02:10

Enrico Campidoglio


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.

like image 44
Ladislav Mrnka Avatar answered Oct 13 '22 00:10

Ladislav Mrnka