我正在被迫連接到正在開發的VBA工具中的某些.net服務。我使用一個函數返回緩存的實例,或者創建一個新的函數,如果它尚未創建。VBA - 在引發異常之前檢查System.ServiceModel.Channels.ServiceChannel發生故障狀態
如果出現任何錯誤與對象(如連接超時),下一次我嘗試使用它,我得到的錯誤
通信對象,System.ServiceModel.Channels.ServiceChannel ,因爲它處於Faulted狀態,所以不能用於通信。
我已經看到這個錯誤在網絡上彈出,但所有的都有適當的語言,有try-catch塊。
當緩存實例被使用並在「On Error Goto」語句中處理它時,我不想等待這個錯誤發生,而是希望在緩存對象被檢索使用時避免它發生。我無法在任何地方找到這個東西的對象模型,並且在初始化的對象上設置一個監視器就會顯示出來。我可以在檢索時使用哪些屬性或測試來確定對象是否處於故障狀態?
Private Function GetMRLDIntegrationService() As Object
Const ServiceAddress = "service:mexAddress=""net.tcp://hydfwdvweb001/Integration/MrldIntegrationService.svc/Mex""," & _
"address=""net.tcp://hydfwdvweb001/Integration/MrldIntegrationService.svc/""," & _
"contract=""IMrldSimplexIntegration"", contractNamespace=""http://tempuri.org/""," & _
"binding=""SimplexIntegration"", bindingNamespace=""http://tempuri.org/"""
Static cachedInstance As Object
If Not cachedInstance Is Nothing Then
''//If *DETECT ERROR STATE HERE* Then Set cachedInstance = Nothing
End If
If cachedInstance Is Nothing Then Set cachedInstance = GetObject(ServiceAddress)
If cachedInstance Is Nothing Then Err.Raise 1, , _
"The MRLD server did not respond to the request to provide the service object."
Set GetMRLDIntegrationService = cachedInstance
End Function
在其他地方,另一種方法,這是在錯誤發生時,這是當它來不及處理與優雅的錯誤:
Private Sub FillFromRiskID(ByVal riskID As String)
...
Process_MRLD_Result GetMRLDIntegrationService().GetSerializedRisk(riskID, "1", uName, pWord)
...
End Sub
感謝您的幫助
無法做到這一點,因爲假性請求只需只要一個正常的處理,加倍每次通話的時間。 – Alain 2011-04-05 16:25:57