Example #1
0
        /// <summary>
        /// 實現Invoke方法
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public override IMessage Invoke(IMessage msg)
        {
            IMethodReturnMessage methodReturnMessage = null;
            IMethodCallMessage   methodCallMessage   = msg as IMethodCallMessage;

            if (methodCallMessage != null)
            {
                IConstructionCallMessage constructionCallMessage = methodCallMessage as IConstructionCallMessage;
                if (constructionCallMessage != null)
                {
                    RealProxy defaultProxy = RemotingServices.GetRealProxy(_target);
                    defaultProxy.InitializeServerObject(constructionCallMessage);
                    methodReturnMessage = EnterpriseServicesHelper.CreateConstructionReturnMessage(constructionCallMessage, (MarshalByRefObject)GetTransparentProxy());
                }
                else
                {
                    _interception.PreInvoke(methodCallMessage);
                    try
                    {
                        methodReturnMessage = RemotingServices.ExecuteMessage(_target, methodCallMessage);
                    }
                    catch { }
                    if (methodReturnMessage.Exception != null)
                    {
                        _interception.ExceptionHandle(methodReturnMessage);
                    }
                    else
                    {
                        _interception.PostInvoke(methodReturnMessage);
                    }
                }
            }
            return(methodReturnMessage);
        }
Example #2
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);
        }