Shortening DNS timeout for SOAP

froodley

Active member
Joined
Apr 20, 2010
Messages
26
Programming Experience
1-3
Hi, all,

I use a web service to access our internal databases. The problem I'm having is that a call to the service is part of my application startup, and when the computer is offline or the server is otherwise unreachable, the DNS call is taking much too long to timeout. I would like to set the value to 2 seconds.

Setting it for the Soap service just sets the timeout for service operations; it doesn't effect the HttpWebRequest object... but that object is being created by the SOAP client, and I don't see that I have access to it to set its timeout.

Is there a simple way to get a quick timeout here?
 
Timeout can be set with .InnerChannel.OperationTimeout property for Service References, and Timeout property for Web References.
 
I tried the Timeout property; it only effects how long the application will wait for a response to an XML request. A DNS request is not effected. If I set the m_service.timeout property to 2000ms while I am online and can reach the service, the timeout for the XML request takes two seconds. But if I use that setting while offline, there is a 10-15 second delay before the service kicks back a DNS request failure exception from its HTTPWebRequest object.
 
That sounds as a network problem, not a webservice request one. So you should be able to detect network before attempting the service request, something a la this perhaps: My.Computer.Network.IsAvailable Property or this My.Computer.Network.Ping Method. When I tested agaist a non-operational service (ie connected to network, but no server at endpoint thus no response for url) the timeout took effect immediately.
 
Thanks, I gave that a try...

Unfortunately the Ping request takes the same amount of time to fail its DNS lookup.

When it fails, it throws a PingException with an inner exception of type System.Net.Sockets.SocketException with this stack trace:

VB.NET:
at System.Net.Dns.GetAddrInfo(String name)
   at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)
   at System.Net.Dns.GetHostAddresses(String hostNameOrAddress)
   at System.Net.NetworkInformation.Ping.Send(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options)

system.network.dns.gethostentry returns the same error, also after about 15 seconds.

I need to find some way to set the DNS timeout.


I have read that you can use an asynchronous request and a timer to get this effect, but haven't seen a code sample... If someone can explain how to use system.network.dns.begingethostentry to do this, I would be very grateful.
 
Back
Top