views:

54

answers:

4

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?

A: 

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.

Dr. Wily's Apprentice
That is what I am changing (On the Client). The ws is an external ws which I don't have access to.
Jim
and yes I am setting WebClientProtocol.Timeout = 5
Jim
A: 

Here is the answer I was looking for: http://stackoverflow.com/questions/1500955/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.
Jim
A: 

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

Kiran Bheemarti
+1  A: 

You could perform the DNS lookup yourself with a shorter timeout (e.g. 1000 ms):

http://www.chapleau.info/cs/blogs/fchapleau/archive/2008/09/09/reverse-dns-lookup-with-timeout-in-c.aspx

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.

Andreas Paulsson