I am making a call to an external service using a web reference. The IP's are dynamic so I call them one by one, and everything works fine. Periodically some of the IP's won't be available and I am getting a timeout which I am handling. The issue is the length of time it takes to timeout is around 30 seconds for each call. I tried changing the timeout property on the ws to 5 seconds but it doesn't seem to make a difference. Can someone please help me with this?
-
1Could you post some code of how you are calling the service and how you are setting the timeout? – taylonr Aug 24 '10 at 18:22
-
//Global Property private WebService.Service1 _ws = new WebService.Service1(); //In Constructor _ws.Timeout = 5000; //Method Call return _ws.create_session(string.Concat(_Domain, @"\", _UserName), _Password, out lErrorCode); – Jim Aug 24 '10 at 18:27
-
Unless there's more information available on this problem, then I'd just recommend a thorough debugging session. Step through the code and make absolutely sure that it is the call to the web service and not something else that is taking so long. If it is, then while you're stepping through the code, check what the value of the Timeout property is at the time that the call is made. You may have set Timeout to 5000 earlier, but perhaps something else set it differently. – Dr. Wily's Apprentice Aug 24 '10 at 20:45
-
I appreciate your response, but I did just that. I walked through the code and validated that the timeout was 5000 right before the ws call. – Jim Aug 24 '10 at 21:08
4 Answers
Here is the answer I was looking for: Adjusting HttpWebRequest Connection Timeout in C#
****Important Snippet:****
From the MSDN documentation of the HttpWebRequest.Timeout
property:
A Domain Name System (DNS) query may take up to 15 seconds to return or time out. If your request contains a host name that requires resolution and you set Timeout to a value less than 15 seconds, it may take 15 seconds or more before a WebException is thrown to indicate a timeout on your request.
You could perform the DNS lookup yourself with a shorter timeout (e.g. 1000 ms):
And then (if a IP address was found) perform the Web Service call using the IP address (to avoid the DNS lookup where You cannot control the timeout) using a TimeOut of e.g. 4000 ms (or even better : 5000ms - (the time the DNS lookup took)) to achieve a total timeout of 5000 ms.

- 7,745
- 3
- 25
- 31
You say that you changed "the timeout property on the ws to 5 seconds". If you're changing the timeout on the server, then that's not going to help you when your client can't connect.
You're using a "web reference", so I assume you have a client class derived from System.Web.Services.Protocols.SoapHttpClientProtocol
. That class derives from System.Web.Services.Protocols.WebClientProtocol
, which has a Timeout property. Try changing that property on your client before making the call and see if you get better results.

- 10,212
- 1
- 25
- 27
-
That is what I am changing (On the Client). The ws is an external ws which I don't have access to. – Jim Aug 24 '10 at 18:41
-
It might help if you ping the IP address before creating a proxy object and calling the web service here is the details on Ping class http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping.aspx

- 1,439
- 2
- 12
- 14