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 に答える