3
votes

I occasionally get SOAP time outs and I am sure it is the connect time out that is causing the problem. After 30 seconds, I always get a time out. By googling, I found suggestions to InternetSetOption that can be used to set the time outs, however on my machine, I have SOAPHttpTrans.pas (CodeGear Delphi 7) which has the following code:

Request := HttpOpenRequest(FInetConnect, 'POST', PChar(FURLSite), nil,
                           nil, nil, Flags, 0{Integer(Self)});
Check(not Assigned(Request));
{ Timeouts }
if FConnectTimeout > 0 then
  Check(not InternetSetOption(Request, INTERNET_OPTION_CONNECT_TIMEOUT, Pointer(@FConnectTimeout), SizeOf(FConnectTimeout)));
if FSendTimeout > 0 then
  Check(not InternetSetOption(Request, INTERNET_OPTION_SEND_TIMEOUT, Pointer(@FSendTimeout), SizeOf(FSendTimeout)));
if FReceiveTimeout > 0 then
  Check(not InternetSetOption(Request, INTERNET_OPTION_RECEIVE_TIMEOUT, Pointer(@FReceiveTimeout), SizeOf(FReceiveTimeout)));

How can I set the connect time out?

JD

2
In my code I have set RIO.HTTPWebNode.ConnectTimeout := 300000; // 5 mins; RIO.HTTPWebNode.SendTimeout := 300000; RIO.HTTPWebNode.ReceiveTimeout := 1200000; // 20 mins. I am sure it is the connecttimeout that is not being applied. - JD.
Have you debugged those lines to see if InternetSetOptions is actually called with correct timeout values? Have you verified the actual timeout values after with InternetQueryOption? - Ondrej Kelle
@SimaWB It has similarities, yes. It's not a complete duplicate, though. In this case it could be that the server is having a timeout too. If the server is IIS with ASP.NET code then you might want to examine the server code too, checking for possible timeout values set there. (In config file, check /configuration/system.web/httpRuntime/@executionTimeout) - Wim ten Brink
Thanks guys for all the help. - JD.

2 Answers

5
votes

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

1
votes

IIRC, InternetSetOption didn't work with IE6 wininet.dll. If it's your case, try upgrading to IE7 or later.