views:

201

answers:

1

Hi,

I have a client application that makes SOAP requests. I have set the timeout to 20 minutes. However, sometimes I see the timeout error occurring after 10 seconds. I have the following in code:

RIO.HTTPWebNode.ReceiveTimeout := 1200000

Do I need to set the ConnectTimeout and SendTimeOut? Currently they are set to the default values of 0. What difference would setting these make?

I am using Delphi 2007.

Looking further at the error message I see I get "The operation timed out....". So should I be setting my ReceiveTimeOut to zero since I really do not want any timeout at all?

+2  A: 

CodeGear's SOAPHTTPTrans implementation sets timeouts globally, not per session. Here's the relevant code from THTTPReqResp.Send:

{ Timeouts }
if FConnectTimeout > 0 then
  Check(not InternetSetOption({Request}nil, INTERNET_OPTION_CONNECT_TIMEOUT, Pointer(@FConnectTimeout), SizeOf(FConnectTimeout)));
if FSendTimeout > 0 then
  Check(not InternetSetOption({Request}nil, INTERNET_OPTION_SEND_TIMEOUT, Pointer(@FSendTimeout), SizeOf(FSendTimeout)));
if FReceiveTimeout > 0 then
  Check(not InternetSetOption({Request}nil, INTERNET_OPTION_RECEIVE_TIMEOUT, Pointer(@FReceiveTimeout), SizeOf(FReceiveTimeout)));

What I've had to do to is use the OnBeforePost handler to set the timeouts:

transport.OnBeforePost := configureHttpRequest;

procedure Tsomething.configureHttpRequest(const HTTPReqResp: THTTPReqResp; Data: Pointer);
begin
  InternetSetOption(Data, INTERNET_OPTION_CONNECT_TIMEOUT, Pointer(@FconnectTimeoutMS), SizeOf(FconnectTimeoutMS));
  InternetSetOption(Data, INTERNET_OPTION_SEND_TIMEOUT, Pointer(@FsendTimeoutMS), SizeOf(FsendTimeoutMS));
  InternetSetOption(Data, INTERNET_OPTION_RECEIVE_TIMEOUT, Pointer(@FreceiveTimeoutMS), SizeOf(FreceiveTimeoutMS));
end;

The MSDN documentation for these options is found at http://msdn.microsoft.com/en-us/library/aa385328%28VS.85%29.aspx

glob
Thank you so much glob. Any ideas why I would get a timed out operation even after a few seconds?
JD
no, not 10 seconds. the default timeout varies with the installed IE version -- with IE7 it's 30 seconds. and as the default code sets the timeout globally, you may hit problems should other code change the timeout. i always explicitly set the timeout as per the code in my answer.
glob