0

I am working on a .Net Remoting project. and I want to monitor the remote calls and returned values or possible exceptions. I Implemented the 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

when the service throws an exception ReplyMsg only contains the LogicalCallContext. how can i find the exception types?

2 Answers2

0

I'm not sure what type your _NextMessageSink is, but if I look at BinaryClientFormatterSink it will wrap any exception within a ReturnMessage. ReturnMessage implements IMethodReturnMessage that provides an Exception property. So it's possible the following may work:

IMethodReturnMessage returnMessage = replyMsg as IMethodReturnMessage;
if (returnMessage != null)
{
    Exception exception = returnMessage.Exception;
    ...
}
nblackburn
  • 338
  • 2
  • 10
0

as the following code is my case. you have to unbox "replyMsg" to check exception or not.

ReturnMessage replyMsgEntity = replyMsg as ReturnMessage;
if(replyMsgEntity != null && replyMsgEntity.Exception != null)
{
    //# TRACE-EXCEPTION....
}
A Tsai Kao
  • 31
  • 2