0

我正在做一个 .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。我怎样才能找到异常类型?

4

2 回答 2

0

我不确定您的_NextMessageSink 是什么类型,但是如果我查看BinaryClientFormatterSink,它将在ReturnMessage 中包含任何异常。ReturnMessage 实现提供 Exception 属性的 IMethodReturnMessage。因此,以下可能会起作用:

IMethodReturnMessage returnMessage = replyMsg as IMethodReturnMessage;
if (returnMessage != null)
{
    Exception exception = returnMessage.Exception;
    ...
}
于 2013-03-13T13:13:07.487 回答
0

因为以下代码是我的情况。您必须取消框“replyMsg”以检查异常与否。

ReturnMessage replyMsgEntity = replyMsg as ReturnMessage;
if(replyMsgEntity != null && replyMsgEntity.Exception != null)
{
    //# TRACE-EXCEPTION....
}
于 2015-11-13T07:44:49.317 回答