locked
Configure a timeout in web.config for a web service RRS feed

  • Question

  • User-1668256174 posted

    Hello everybody,
    I have a web service hosted in IIS 7.5.
    The web service works fine.
    I try to configure a timeout in the web.config, but I can't do it.
    I tried in my web.config :

    <Configuration>
    <system.web>
    <compilation debug="false" targetFramework="4.8" />
    <httpRuntime targetFramework="4.8" executionTimeout="10" /> <!-- 10 seconds -->
    <sessionState timeout="2" /> <!-- 2 minutes -->
    </system.web>
    </Configuration>

    and in the web service controller :

    Thread.Sleep(180000) //3 minutes

    I thought the execution would stop after 10 seconds but instead it stops after 1 minute, whatever I put in the "executionTimeout" and "timeout" parameters.

    I have searched in IIS but impossible to find what this minute corresponds to.

    Does someone have an idea ?

    Thanks a lot in advance.

    Eric.

    Friday, June 19, 2020 7:11 PM

All replies

  • User288213138 posted

    Hi eric.bryan,

    <httpRuntime targetFramework="4.8" executionTimeout="10" /> <!-- 10 seconds -->

    Thread.Sleep(180000) //3 minutes

    As far as i know, The httpruntime executionTimeout cannot affect Thread Sleep.

    I thought the execution would stop after 10 seconds but instead it stops after 1 minute, whatever I put in the "executionTimeout" and "timeout" parameters.

    I have searched in IIS but impossible to find what this minute corresponds to.

    If you want to set the executionTimeout in the iis, you can change it by setting the connection time out attribute in iis.

    Best regards,

    Sam

    Monday, June 22, 2020 9:53 AM
  • User-1668256174 posted

    Hi Sam,

    Thanks for your reply.

    I am not sure to understand : you say that executiontimeout must be used in association with <sessionState timeout="??"> : it cannot be used alone ?

    In my example, I use them both.

    And to simulate a long execution time, may I set a delay in a sql server stored procedure that is called instead of the "Thread.Sleep(180000)" ?

    Best regards.

    Eric.

    PS : I understood what you said about connectionTimeout : I set it in IIS but it's the same.

          Do I have to set both connectionTimeout and executiontimeout for it to work ?

    Monday, June 22, 2020 10:14 AM
  • User288213138 posted

    Hi eric.bryan,

    I am not sure to understand : you say that executiontimeout must be used in association with <sessionState timeout="??"> : it cannot be used alone ?

    In my example, I use them both.

    And to simulate a long execution time, may I set a delay in a sql server stored procedure that is called instead of the "Thread.Sleep(180000)" ?

    I think you misunderstood what I meant, I mean the Thread.Sleep() method has nothing to do with the executionTimeout you set.

    Do I have to set both connectionTimeout and executiontimeout for it to work ?

    The ConnectionTimeout property specifies the amount of time (in seconds) that the server waits before disconnecting an inactive connection. 

    And the HttpRuntimeSection.ExecutionTimeout Property gets or sets the allowed execution time for the request.

    So there is no relationship between them.

    Best regards,

    Sam

    Tuesday, June 23, 2020 8:00 AM
  • User-1668256174 posted

    Sam,

    Sorry for the delay.

    Thank you for your answer.

    In fact I use now CancellationToken which can stop a Task or a Thread after a number of milliseconds.

    Here is the explanations link :

    https://stackoverflow.com/questions/42268735/how-to-stop-a-thread-if-thread-takes-too-long

    Best regards.

    Eric.

    Friday, July 3, 2020 1:17 PM