我正在被迫连接到正在开发的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