开发者

Web service time out errors in Delphi

开发者 https://www.devze.com 2023-01-01 08:17 出处:网络
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 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 followin开发者_开发技巧g 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消