tags:

views:

115

answers:

2

Hi,

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

+1  A: 

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

TOndrej
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
+2  A: 

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
Hi glob, was this prior to d2007?
JD
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
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
good to hear -- feel free to accept my answer :)
glob