1

How can I enable/disable the HTTP Keep-alive and set the connection timeout of a self hosted service using the application configuration and the C# ServiceHost?

For example,

MyService service = new MyService();
ServiceHost serviceHost = new ServiceHost(service);
serviceHost.Open();

What do I have to put in the application configuration to set the http keep alive and timeout.

<configuration>
  <system.serviceModel>
  <services>
    <service name="MyService" behaviorConfiguration="myServiceBehavior">
    <endpoint address="http://localhost:9005/"
          binding="webHttpBinding"
          contract="IMyService"
          behaviorConfiguration="myServerEndpointBehavior"/>
    </service>
  </services>
  </system.serviceModel>
  <!-- WHERE TO ENABLE/DISABLE http keep alive and timeout -->
</configuration>

The settings under IIS are found if you go to the IIS Manager. Right click on the "Default Web Site"->Properties->Web Site->Connections. Can I do that through the system.serviceModel configuration?

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
Hemant Kumar
  • 4,593
  • 9
  • 56
  • 95
  • I solved this, see here http://stackoverflow.com/questions/14266854/what-130-second-timeout-is-killig-my-wcf-streaming-service-call – Luiz Felipe Aug 27 '13 at 17:01

1 Answers1

2

Keep alive for http connections is turned on by default. If you want to turn it off you must create custom binding:

<bindings>
    <customBinding>
        <binding name="WebHttpWithoutKeepAlive">
            <webMessageEncoding />
            <httpTransport keepAliveEnabled="false" />
        </binding>
    </customBinding>
</bindings>
<services>
    <service name="MyService" behaviorConfiguration="myServiceBehavior">
    <endpoint address="http://localhost:9005/"
          binding="customBinding"
          bindingConfiguration="WebHttpWithoutKeepAlive"
          contract="IMyService"
          behaviorConfiguration="myServerEndpointBehavior"/>
    </service>
</services>

How to set a keep-alive timout is a mystery. There is no "service timeout" in your scenario (it makes sense only in bindings with session) and keep-alive timeout doesn't abort communication between client and service.

Btw. your example code defines service as singleton object.

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670