Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi - How set SoapClient Timeout?

I'm doing this before post:

FTimeout := 30000;

InternetSetOption(Pointer(@Data), INTERNET_OPTION_CONNECT_TIMEOUT, Pointer(@FTimeOut), SizeOf(FTimeOut));
InternetSetOption(Pointer(@Data), INTERNET_OPTION_SEND_TIMEOUT, Pointer(@FTimeOut), SizeOf(FTimeOut));
InternetSetOption(Pointer(@Data), INTERNET_OPTION_RECEIVE_TIMEOUT, Pointer(@FTimeOut), SizeOf(FTimeOut));

But don't works.

Someone can help?

like image 654
DavidRigamonte Avatar asked Apr 15 '26 05:04

DavidRigamonte


1 Answers

That should work. You don't say where you call it from, but I call mine in the OnBeforePost handler.

My function looks like this:

function SetTimeout(const HTTPReqResp: THTTPReqResp; Data: Pointer; NumSecs : integer) : boolean;
var
  TimeOut: Integer;
begin
  // Sets the receive timeout. i.e. how long to wait to 'receive' the response
  TimeOut := (NumSecs * 1000);
  try
    InternetSetOption(Data, INTERNET_OPTION_RECEIVE_TIMEOUT,  Pointer(@TimeOut),  SizeOf(TimeOut));
    InternetSetOption(Data, INTERNET_OPTION_SEND_TIMEOUT,  Pointer(@TimeOut),  SizeOf(TimeOut));
  except on E:Exception do
    raise Exception.Create(Format('Unhandled Exception:[%s] while setting timeout to [%d] - ',[E.ClassName, TimeOut, e.Message]));
  end;
end;
like image 194
Chris Thornton Avatar answered Apr 17 '26 03:04

Chris Thornton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!