2011-03-25 5 views
1

저는 개발중인 VBA 도구에서 일부 .net 서비스에 연결해야합니다. 함수를 사용하여 캐시 된 인스턴스를 반환하거나 아직 생성되지 않은 경우 새 인스턴스를 만듭니다. 아무것도 (예 : 밖으로 연결 시간으로) 객체와 잘못되면VBA - 예외를 발생시키기 전에 System.ServiceModel.Channels.ServiceChannel 오류 상태 확인

, 내가 그것을 사용하려고 다음에, 나는 오류를

통신 개체, System.ServiceModel.Channels.ServiceChannel를 얻을 수 오류 상태이므로 통신에 사용할 수 없습니다.

이 오류는 웹 전체에서 팝업으로 표시되지만 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 

는 다른 방법으로,이이며,이는 우아하게 에러를 처리하기 위해 너무 늦기 때이다 : 도움

답변

0

이 대체 솔루션이의 getService이 (오류가 발생 즉 경우) 캐시 된 개체를 다시 설정하는 옵션 기능을 제공, 문제는 내가이 기능을 사용하는 방법을 찾을 수 있다는 것입니다 같은 오류 상태 오류가 쉽게 할 수 리셋되지만 실제 오류가 처리되기 전에 다른 오류로 인해 중복 된 오류가 발생하지 않습니다.

Private Function GetMRLDIntegrationService(Optional ByVal reset As Boolean = False) 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 reset Then Set cachedInstance = Nothing 
    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 

그리고 호출 기능 :

''/*If the cached object is in an error state there's no way to detect it without making a request, but 
'making even a dummy request each use just to check would waste dozens of precious seconds per request, 
'so this routine carefully makes the intended request, catches the error that might occur, then resets 
'the connection and tries the request again. The upside is that a service object in an error state 
'will be resolved immediately and transparently by opening a new connection as needed. The downside 
'is that if any other error occurs (such as a 1 minute timeout error), the first occurrence will 
'be a non-breaking error and it will actually repeat the error a second time before notifying the user, 
'doubling the amount of time it takes any error to propogate. (In the case of a 1 minute time-out 
'occurring, the request would occur twice for a total of 2 minutes delay until the application becomes 
'responsive again.)*/ 
Private Sub FillFromRiskID(ByVal riskID As String) 
    Const uName As String = "perftest1" 
    Const pWord As String = "****" 
    Dim result As String 

    On Error GoTo retryGet 
    Process_MRLD_Result GetMRLDIntegrationService().GetSerializedRisk(riskID, "1", uName, pWord) 
    GoTo finally 
retryGet: 
    Resume retryGet2: 'Resets the error state so that a new error can be thrown 
retryGet2: 
    On Error GoTo invalidConnection 
    Process_MRLD_Result GetMRLDIntegrationService(reset:=True).GetSerializedRisk(riskID, "1", uName, pWord) 
finally: 
    Exit Sub 
invalidConnection: 
    MsgBox "Error connecting to MRLD: " & Err.Description, vbCritical, "Fill From MRLD" 
End Sub 
0

이를위한

Private Sub FillFromRiskID(ByVal riskID As String) 
    ... 
    Process_MRLD_Result GetMRLDIntegrationService().GetSerializedRisk(riskID, "1", uName, pWord) 
    ... 
End Sub 

감사합니다 작동하는 솔루션이지만, 캐시 된 객체에 아무런 문제가없는 대부분의 경우 시간이 낭비되기 때문에 피하려고 노력하고 있습니다. GetSerializedRisk는 반환 값이 잘못된 로그인 또는 잘못된 요청 ID 일지라도 경우에 따라 반환되는 데 15 초 정도 걸립니다.

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 
     On Error GoTo errorStateDetected 
     cachedInstance.GetSerializedRisk "1", "1", "dummyrequest", "dummyrequest" 
     GoTo everythingIsFine 
errorStateDetected: 
     Set cachedInstance = Nothing 
     Resume everythingIsFine 
everythingIsFine: 
     ''//I just wasted a bunch of time 
    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 
+0

더미 요청이 각 통화 시간을 두 배로, 일반 하나로 처리 할만큼 오래 걸리기 때문에이 작업을 수행 할 수 없습니다. – Alain