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?

4
  • 1
    Could you post some code of how you are calling the service and how you are setting the timeout? Commented Aug 24, 2010 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); Commented Aug 24, 2010 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. Commented Aug 24, 2010 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. Commented Aug 24, 2010 at 21:08

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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.

2 Comments

That is what I am changing (On the Client). The ws is an external ws which I don't have access to.
and yes I am setting WebClientProtocol.Timeout = 5
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.