Delphi中的Web服务超时错误 [英] Web service time out errors in Delphi
问题描述
我有一个发出SOAP请求的客户端应用程序.我已将超时设置为20分钟.但是,有时我会看到10秒后发生超时错误. 我在代码中有以下内容:
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
是否需要设置ConnectTimeout
和SendTimeOut
?当前,它们设置为默认值0.设置这些参数会有什么区别?
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?
我正在使用Delphi 2007.
I am using Delphi 2007.
进一步查看错误消息,我看到操作超时....".那我应该将ReceiveTimeOut
设置为零,因为我真的根本不想超时吗?
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的SOAPHTTPTrans
实现全局设置超时,而不是针对每个会话设置超时.这是THTTPReqResp.Send
中的相关代码:
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)));
我要做的是使用OnBeforePost
处理程序来设置超时时间:
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;
这些选项的MSDN文档位于 http://msdn.microsoft.com/zh-cn/library/aa385328%28VS.85%29.aspx
The MSDN documentation for these options is found at http://msdn.microsoft.com/en-us/library/aa385328%28VS.85%29.aspx
这篇关于Delphi中的Web服务超时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!