Timeout Error when calling webservice

Posted on 2011-10-26
Last Modified: 2012-06-27
In my web site I am calling web service which works fine most of time but sometimes it give timeout error. see error below

"System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream() at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) "

In my website web.config I had increased the timeout in following
<httpRuntime executionTimeout
<sessionState mode="InProc" timeout="
but still sometimes i get this timeout error when calling webservice

Any suggestion how to reolve this issue?

Should I need to increase the timeout on the server where the webservice is hosted if yes how can I do it?

Question by:shieldguy
    LVL 17

    Expert Comment

    by:Carlos Villegas
    Hello, the System.Web.Services.Protocols.SoapHttpClientProtocol class has the Timeout property, the default value is 100000 ms (100 seconds), you can try by increasing this value on your client proxy, but I don't like too much this way... can you provide more info about your service so I can have a better view of what is going on? how many users access it? is hosted on IIS6/7? what is the average time for this method to complete? what you do inside your web method, connections to DB, file access, network access, etc..?

    LVL 1

    Author Comment

    This web service normally take about 20 - 40 secs to complete

    It perform two task first get the payment details varification and second save the order details to the ERP system

    Currently the problem is that I dont have the access to the code of web service

    LVL 17

    Accepted Solution

    Ok, you must take in consideration that network errors can happen, maybe instead of increasing the timeout value you can implement this small logic when you call that web service, if it throw you a timeout exception you can try one more time, if there is another timeout exception then something must be wrong and you can display a friendly message to your user, something like "try again in a few seconds".
    int tryCounter = 0;
    catch (TimeoutException)
        if (tryCounter < 2)
            goto tryAgain;

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    To properly understand GitHub, let’s divide it into two words ‘Git’ and ‘Hub’. Git is basically a ‘Distribution Version Control’ (DVC) and ‘Source Code Management’ (SCM) system widely used by software programmers while Hub means the efficient centre…
    The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
    This video is a brief demonstration on how to use security groups and Network Access Control Lists (ACLs) in Amazon Web Services.  Security groups and Network ACLs are mechanisms you can use in AWS to control network traffic.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now