Jim
Jim

Reputation: 51

C# Web Reference Call Timeout

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?

Upvotes: 4

Views: 8689

Answers (4)

Jim
Jim

Reputation: 51

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.

Upvotes: 1

Andreas Paulsson
Andreas Paulsson

Reputation: 7803

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.

Upvotes: 1

Kiran Bheemarti
Kiran Bheemarti

Reputation: 1459

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

Upvotes: 0

Dr. Wily's Apprentice
Dr. Wily's Apprentice

Reputation: 10280

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.

Upvotes: 0

Related Questions