Increasing the timeout value in a WCF service - Stack Overflow

admin2023-02-27  370

How do I increase the default timeout to larger than 1 minute on a WCF service?


How do I increase the default timeout to larger than 1 minute on a WCF service?


Are you referring to the server side or the client side?

For a client, you would want to adjust the sendTimeout attribute of a binding element. For a service, you would want to adjust the receiveTimeout attribute of a binding elemnent.

      <binding name="longTimeoutBinding"
        receiveTimeout="00:10:00" sendTimeout="00:10:00">
        <security mode="None"/>

    <service name="longTimeoutService"
      <endpoint address="net.tcp://localhost/longtimeout/"
        binding="netTcpBinding" bindingConfiguration="longTimeoutBinding" />

Of course, you have to map your desired endpoint to that particular binding.


Under the Tools menu in Visual Studio 2008 (or 2005 if you have the right WCF stuff installed) there is an options called 'WCF Service Configuration Editor'.

From there you can change the binding options for both the client and the services, one of these options will be for time-outs.


You can choose two ways:

1) By code in the client

public static void Main()
    Uri baseAddress = new Uri("http://localhost/MyServer/MyService");

        ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService));

        WSHttpBinding binding = new WSHttpBinding();
        binding.OpenTimeout = new TimeSpan(0, 10, 0);
        binding.CloseTimeout = new TimeSpan(0, 10, 0);
        binding.SendTimeout = new TimeSpan(0, 10, 0);
        binding.ReceiveTimeout = new TimeSpan(0, 10, 0);

        serviceHost.AddServiceEndpoint("ICalculator", binding, baseAddress);

        // The service can now be accessed.
        Console.WriteLine("The service is ready.");
        Console.WriteLine("Press <ENTER> to terminate service.");

    catch (CommunicationException ex)
        // Handle exception ...

2)By WebConfig in a web server

        <binding openTimeout="00:10:00" 

For more detail view the official documentations

Configuring Timeout Values on a Binding

Class WSHttpBinding


Different timeouts mean different things. When you're working on the client.. you're probably looking mostly at the SendTimeout - check this reference - wonderful and relevant explanation:

It says:

Brief summary of binding timeout knobs...

Client side:

SendTimeout is used to initialize the OperationTimeout, which governs the whole interaction for sending a message (including receiving a reply message in a request-reply case).  This timeout also applies when sending reply messages from a CallbackContract method.
OpenTimeout and CloseTimeout are used when opening and closing channels (when no explicit timeout value is passed).
ReceiveTimeout is not used.

Server side:

Send, Open, and Close Timeout same as on client (for Callbacks).
ReceiveTimeout is used by ServiceFramework layer to initialize the session-idle timeout.


In addition to the binding timeouts (which are in Timespans), You may also need this as well. This is in seconds.

    <httpRuntime executionTimeout="600"/><!-- = 10 minutes -->

New Post(0)