2012-12-26 23 views
0

我正在開發.Net Remoting項目。我想監視遠程調用和返回值或可能的異常。 我實現了IMessageSink確定回覆的消息是否包含.Net Remoting通道中的異常IMessageSink

Public Function SyncProcessMessage(ByVal msg As System.Runtime.Remoting.Messaging.IMessage) As System.Runtime.Remoting.Messaging.IMessage Implements System.Runtime.Remoting.Messaging.IMessageSink.SyncProcessMessage 

     Dim replyMsg As IMessage = _NextMessageSink.SyncProcessMessage(msg) 

     if {ReplyMsg Contains Exception of type a} then 
      do something 
     else if {ReplyMsg Contains Exception of type b} then 
      do someshing else 
     End If 

     Return replyMsg 
    End Function 

服務時拋出異常ReplyMsg只包含LogicalCallContext。 我怎麼找到異常類型?

+0

順便說一句,我希望你知道Remoting已被棄用,贊成WCF? –

+0

是的,但是這是一個龐大的系統,並在幾年前實施,我們現在無法移動到WCF,我只是在改變ChannelSinks。 – user1929392

回答

0

我不確定你的_NextMessageSink是什麼類型,但是如果我看看BinaryClientFormatterSink,它會包裝ReturnMessage中的任何異常。 ReturnMessage實現了提供Exception屬性的IMethodReturnMessage。所以有可能以下工作:

IMethodReturnMessage returnMessage = replyMsg as IMethodReturnMessage; 
if (returnMessage != null) 
{ 
    Exception exception = returnMessage.Exception; 
    ... 
} 
0

如下面的代碼是我的情況。你必須解開「replyMsg」來檢查異常與否。

ReturnMessage replyMsgEntity = replyMsg as ReturnMessage; 
if(replyMsgEntity != null && replyMsgEntity.Exception != null) 
{ 
    //# TRACE-EXCEPTION.... 
} 
相關問題