1

我直接调用了由 iis 托管的 wcf 服务,我是 Delphi 2010

对服务调用的操作可能需要几分钟时间

在 Delphi 中避免超时错误的最佳方法是什么?

我故意在我的 WCF 服务中放置一个 Thread.Sleep 强制它等待 31 秒

30秒后我得到了错误

项目引发异常类 ESOAPHTTPException 并带有消息“请求操作的句柄处于错误状态 - URL:http://10.1.1.4/STC.WcfServices.Host/FlexProcurementService.svc - SOAPAction:http://navsl.stcenergy。 com/FlexProcurement/FlexProcurementService/GetPassthroughSummaryGridReportData'。

原来这是我已经应用补丁的 Delphi 2010 中的一个错误,所以现在我得到错误操作超时

function GetFlexProcurementService(const objServiceInfo: TWCFService; UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): FlexProcurementService;
var
  RIO: THTTPRIO;
begin
  Result := nil;
  if (Addr = '') then
  begin
    if UseWSDL then
      Addr := objServiceInfo.WSDL
    else
      Addr := objServiceInfo.URL;
end;
if HTTPRIO = nil then
  RIO := THTTPRIO.Create(nil)
else
  RIO := HTTPRIO;
try
  Result := (RIO as FlexProcurementService);
  if UseWSDL then
  begin
    RIO.WSDLLocation := Addr;
    RIO.Service := objServiceInfo.Svc;
    RIO.Port := objServiceInfo.Prt;
  end else
    RIO.URL := Addr;
finally
  if (Result = nil) and (HTTPRIO = nil) then
    RIO.Free;
end;

结尾;

保罗

4

1 回答 1

0
uses wininet;
...

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;

在 RIO OnBeforePost 中:

procedure TEETOUpsertWrapper.OnBeforePost(const HTTPReqResp: THTTPReqResp; Data: Pointer);    begin
  SetTimeout(HTTPReqResp, Data, 5 * 60);
end;
于 2012-09-25T12:27:37.327 回答