2012-09-25 31 views
1

我不得不由IIS託管WCF服務的直接調用我2010如何在Delphi中設置wcf服務調用者的超時時間?

操作德爾福被調用的服務可能需要幾分鐘

什麼是避免在Delphi超時錯誤的最好方式?

我特意把我Thread.sleep代碼WCF服務力裏面等待31秒

30秒後,我得到了錯誤

與消息「手柄項目引發的異常類ESOAPHTTPException是在錯誤狀態的請求的操作 - 網址:HTTP://10.1.1.4/STC.WcfServices.Host/FlexProcurementService.svc - 的SOAPAction:HTTP://navsl.stcenergy.com/FlexProcurement/FlexProcurementService/GetPassthroughSummaryGridReportData」。

事實證明,這是我已經申請了補丁德爾福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; 

末;

保羅

+0

處理錯誤? – TLama

+0

我需要完全避免超時? – Paul

+0

我是不是在工作時,我發送了消息,現在又增加了代碼和錯誤 – Paul

回答

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; 
+0

感謝這個克里斯什麼單位我需要爲InternetSetOption和常量的錯誤嗎? – Paul

+0

wininet。爲了清晰起見,我添加了答案。 –

+0

那麼......它的工作? –