Пример #1
0
        /// <summary>
        /// 执行具体的拦截操作
        /// </summary>
        /// <param name="methodInfo"></param>
        /// <param name="methodCallMessage"></param>
        /// <returns></returns>
        private IMethodReturnMessage Proceed(MethodInfo methodInfo, IMethodCallMessage methodCallMessage)
        {
            if (_enablePreInterception)
            {
                _interception.PreInvoke(methodInfo, methodCallMessage.Args,
                                        _target);
            }

            // 问题1:使用 methodReturnMessage = RemotingServices.ExecuteMessage(_target, methodCallMessage) 方法 不能捕获异常

            Exception methodException = null;

            var methodReturnMessage = SafeExecute(methodCallMessage, ref methodException);

            if (methodException != null)
            {
                _interception.ExceptionHandle(methodInfo, methodCallMessage.Args,
                                              _target, methodException);
            }

            if (_enableAfterInterception)
            {
                _interception.AfterInvoke(methodInfo, methodCallMessage.Args,
                                          _target);
            }
            return(methodReturnMessage);
        }
Пример #2
0
        public override IMessage Invoke(IMessage msg)
        {
            IMethodReturnMessage methodReturnMessage = null;
            var methodCallMessage = msg as IMethodCallMessage;

            if (methodCallMessage != null)
            {
                var constructionCallMessage = methodCallMessage as IConstructionCallMessage;
                if (constructionCallMessage != null)
                {
                    var defaultProxy = RemotingServices.GetRealProxy(_target);
                    defaultProxy.InitializeServerObject(constructionCallMessage);
                    methodReturnMessage =
                        EnterpriseServicesHelper.CreateConstructionReturnMessage(constructionCallMessage,
                                                                                 (MarshalByRefObject)GetTransparentProxy());
                }
                else
                {
                    _interception.PreInvoke(methodCallMessage);
                    try
                    {
                        methodReturnMessage = RemotingServices.ExecuteMessage(_target, methodCallMessage);
                    }
                    catch
                    {
                        // ignored
                    }
                    if (methodReturnMessage?.Exception != null)
                    {
                        _interception.ExceptionHandle(methodReturnMessage.Exception);
                    }
                    else
                    {
                        _interception.AfterInvoke(methodReturnMessage);
                    }
                }
            }
            return(methodReturnMessage);
        }