【问题标题】:Determining if the Replied Message Contains an exception in .Net Remoting Channel IMessageSink确定回复的消息是否包含 .Net Remoting Channel IMessageSink 中的异常
【发布时间】:2012-12-26 09:40:37
【问题描述】:

我正在开发一个 .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。 如何找到异常类型?

【问题讨论】:

  • 顺便说一句,我希望您知道远程处理已被弃用以支持 WCF?
  • 是的,但这是一个庞大的系统,多年前就实施了,我们现在不能迁移到 WCF,我只是在更改 ChannelSinks。

标签: .net exception remoting channel


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2015-10-18
      • 1970-01-01
      • 2023-01-04
      • 2015-12-14
      • 1970-01-01
      • 1970-01-01
      • 2011-07-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多