none
Service timeout issue in C# RRS feed

  • Question

  • Hi Team,

    We have C# code and hosted as windows service in windows server 2008. Which will connect to web service and get the information. But during this process intermittently we receive time out error:

    "The request channel timed out while waiting for a reply after 00:00:59.0504093. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout."

    We increased timeout but still same issue. Can you please tell me what are the scenarios this issue might come and what is the solution ? 

    How we can avoid this issue by implementing any code ? Also normally is this system exception or target system sends ?

    Thanks ..... 

    Tuesday, October 30, 2018 1:50 PM

All replies

  • Increasing the timeout helps but not in all cases. The issue might not be from your end and related to web service you are calling from win service.

    Check the data size that you are returing from web service. If the web service is calling another web service or database, it might be taking more time to fetch the records and thus your windows service is getting timeout. Please check the time taken by the web service to respond. this will help you determine the issue is on your server or network (web service).


    Thanks, AT

    Tuesday, October 30, 2018 2:34 PM
  • Hello,

    How we can avoid this issue by implementing any code ?

    First you need to determine what cause the timeout.

    For this you need to go through server side code and check if there is any kind of timeout. My last one was related with handling of an exception - handler require to send an e-mail and was not able reach an e-mail server as server was relocated to different IP. So, it could be something very unexpected... 

    Also - check your binding: 

    <binding name="BasicHttpBinding_SomeName" closeTimeout="00:01:00"
        openTimeout="00:01:00" receiveTimeout="00:10:00"
        sendTimeout="00:10:00" maxBufferPoolSize="2147483647"
        maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">



    Sincerely, Highly skilled coding monkey.

    Tuesday, October 30, 2018 2:45 PM
  • We have C# code and hosted as windows service in windows server 2008. Which will connect to web service and get the information. But during this process intermittently we receive time out error:

    "The request channel timed out while waiting for a reply after00:00:59.0504093. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout."

    It's timing out on the  server side code and  not  the client side. Whatever is happening is taking too long on the server side code that is beyond the timeout limit of 1 minute. . 

    Tuesday, October 30, 2018 3:00 PM
  • This is a potentially common issue. You sent a request over the network and the web service didn't respond in a timely fashion. This is generally an issue on the web service side, not in your service. It can happen for a variety of reasons including the web service being overloaded, network latency, etc. If it works intermittently then it pretty much indicates a web service side processing issue. It is also possible the web service simply took too long to process the request. This can happen if you are experiencing deadlock issues talking to a database. Again all this is on the web service side, not your application generally.

    The solution would be to fix the web service problem. However even then you'll run into this issue periodically. You'll need to decide how to handle it in your app. In some cases simply catching the error and retrying is appropriate. If it is a GET-type request then this should be the route you go. However if you were making some sort of update call then doing it again could apply the update again. The web service would need to be resilient to retry attempts before you could retry update-like requests.

    You mentioned you updated the timeout but I notice it is still 1 minute which is the default. I suspect you aren't changing the "right" timeout. There are multiple. The timeout you're likely changing is the connection timeout. That just determines how long WCF will wait until it gets a connection to the server. Once connected it then waits for the response. That is a different timeout. It depends upon the binding you're using but since you mentioned web service I assume you're using BasicHttpBinding. For that binding set the receiveTimeout attribute to a higher value. Note that this is really a hack to work around a slow service call then an actual fix. You'll still run into the issue most likely, just less often.

    Finally, you mentioned a windows service so it should be pointed out that you may find a correlation between the timeouts and the service lifetime. If you notice the timeouts only during the initial startup of the service then most likely you have a dependency issue. Since your service requires network access your service would need to have a dependency on the network being online. If your service auto starts then without this dependency it is possible your service will start (and therefore make a network call) before the network has finished initializing. While I would expect a slightly different error in this case I point it out in case you do notice a correlation.


    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, October 30, 2018 3:40 PM
    Moderator
  • Hi Intermediate-User,

    >>How we can avoid this issue by implementing any code ? Also normally is this system exception or target system sends ?

    Maybe you could consider to improve your web service performance to reduce the issue, here is a article about how to Improve Performance of ASP.Net and Web Service for your reference.

    https://www.c-sharpcorner.com/UploadFile/dacca2/improve-performance-of-Asp-Net-and-web-service/

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, October 31, 2018 2:53 AM
    Moderator
  • Hi Wu,

    Thanks for Good explanation. 

    Below code I am using to call GetData web service method.

    // client : We consumed web service in .NET windows application. Webservice is in Java and hosted in Linux server.

    // Below are the code we are using in .NET windows application to call GetData web service method.

     client.Endpoint.Binding.SendTimeout = new TimeSpan(0, 2, 0);

     try
       {
           resp = client.GetData(req); // Calling Java web service hosted in Linux.
           client.Close();                        
       }
       catch (Exception ex)
       {
         //Log if there are any errors during connection
         response.errorMessage = "Service did not respond in time. Error reason: " + ex.Message;
         return response;
       }

    After couple of months it starts throwing error and that time we receive below error:

    "The request channel timed out while waiting for a reply after 00:00:59.0504093. Increase the timeout value passed to the call to Request or increase the Send-timeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout."

    When we restart the web service, it again works for couple of months and provide proper response.

    In this case can you confirm where the issue in.NET windows application side or java web service side ?

    If its Java web service then What all the precautions we can take care in .NET windows applications.

    Please help me here this is very critical for our project.

    Thanks...


    Thursday, November 22, 2018 4:26 AM