3

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

RRUZ
  • 134,889
  • 20
  • 356
  • 483
JD.
  • 15,171
  • 21
  • 86
  • 159
  • 1
    may be duplicated http://stackoverflow.com/questions/2654122/soap-delphi-client-end-with-a-timeout-for-a-1mb-call – SimaWB Oct 12 '10 at 09:48
  • 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. Oct 12 '10 at 09:57
  • 1
    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 Oct 12 '10 at 10:58
  • @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 Oct 12 '10 at 12:00

2 Answers2

5

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
  • 2,960
  • 17
  • 21
  • Hi glob, was this prior to d2007? – JD. Oct 12 '10 at 13:22
  • I use Delphi 2007. There are known bugs in some versions of wininet where it doesn't honour the timeouts -- the workaround for them is use pass NIL as the request, making the timeouts global. – glob Oct 12 '10 at 14:12
  • Thanks. I used that above code but not use NIL and check with InternetQueryOption() and the time outs have disappeared. All seems to be working now. I assume that the code in Delphi 2007 was bug free, clearly not the case. – JD. Oct 14 '10 at 14:50
  • Just for reference: More information about the bugs in timeouts and the workaround is here: http://stackoverflow.com/questions/2898261/web-service-time-out-errors-in-delphi – Neville Cook Feb 05 '14 at 22:34
1

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

Ondrej Kelle
  • 36,941
  • 2
  • 65
  • 128
  • Thanks, we are using IE7 and with have "Codegear Delphi 2007" NOT D7. I do not think it is the receivetimeout that is the issue as I have set a break point on the called app and it times out according to the receivetimeout value. – JD. Oct 12 '10 at 10:11