Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web service time out errors in Delphi

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?

like image 550
JD. Avatar asked May 24 '10 15:05

JD.


1 Answers

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

like image 176
glob Avatar answered Nov 04 '22 08:11

glob