2013-07-05 35 views
0

我有一個經典的ASP頁面,它調用一個外部的web服務。 這是實際過程中是如何工作的:如何延遲執行經典ASP中的部分腳本?

'[Part0 : Call the external webservice] 
wsResponse = setConfirmation(...) 


' [PART1: external webservice is responding]  
if not wsResponse is Nothing then 
'....Process the response from the webservice according to wsResponse 
    code =wsResponse.getCode 
    if code = 'C' then 
    'We confirm the transaction and call a storedprocedure in SqlServer 
    else 
    'if code is different from C, we assume, the transaction status is 'not confirmed' or 'cancelled' 

'[PART2: no answer from external webservice] 
Else 
    'so wsReponse is nothing..We don't get any answer from the external webservice 
    'transaction is not confirmed 
    'the transaction status is set to 'not confirmed' in database 

所以我想要做的是,在PART2(當沒有答案是從外部Web服務獲得),等待30秒之前發出數據庫「未確認」狀態。所以我想再次做PART0即:再次調用外部web服務至少10次,看看它是否響應。一種遞歸過程。 所以我在想這樣做的2路:

  1. 在PART2,把ASP睡30秒,並再次PART0(調用Web服務),如果還是沒有反應,在DB寫,交易未證實,但如果回覆,那麼做PART1。

  2. 在PART2中,調用PART0至少重複10次,如果經過10次試驗後,沒有響應,則寫入DB,交易未確認。

所以我的問題是:有沒有更好的方法來做到這一點或哪些或1或2會更好?還有,對於1,我們如何讓ASP像dotnet或PHP那樣睡覺?

感謝您的回答。

Regards

回答

0

我不知道任何方式把ASP睡覺。特別是當你在一個託管網絡上。所以我會做的是:我會有一個像Pingdom.com這樣的服務來每10秒鐘請求一個ASP頁面。所請求的ASP頁面將參加任何未決事務(以tabel記錄)。

+0

感謝您的答覆,但我不能使用pingdom.com出於很多原因。 – fisdelom

3

下面是一個簡單的子程序,將盡可能多秒延時,因爲你需要

Sub MyDelay(NumberOfSeconds) 
Dim DateTimeResume 
    DateTimeResume= DateAdd("s", NumberOfSeconds, Now()) 
    Do Until (Now() > DateTimeResume) 
    Loop 
End Sub 

只需撥打這個子程序中第2部分

Call MyDelay(30)