public void Intercept(IInvocation invocation)
        {
            var request = new InterfaceCallRequest
            {
                InterfaceType = InterfaceType.FullName,
                Method        = invocation.Method,
                Parameters    = invocation.Arguments
            };

            try {
                invocation.ReturnValue = RemoteProceed?.Invoke(request);
            }
            catch (Exception e) {
                if (ExceptionCatch != null)
                {
                    if (ExceptionCatch.Catch(e, invocation.Proxy, invocation.Method))
                    {
                        throw;
                    }
                }
                else
                {
                    throw;
                }
            }
        }
Пример #2
0
        private object Irpc_RemoteProceed(InterfaceCallRequest request)
        {
            TcpClient client = null;

            try
            {
                client = new TcpClient();
                client.Connect(RemoteChannel);
                // 参数体请求
                SendRequest(CallType.Call, request, client.Client);

                #region 结果接收

                var responseHead = client.Client.GetStruct <ResponseHead>();//GetResponseHead(client.Client);
                if (!responseHead.IsCorrect)
                {
                    throw new IOException("接受到的数据发生损坏!");
                }
                var receiveStream = client.Client.GetSpecificLenStream(responseHead.LeaveLength);
                if (!responseHead.IsProcessSuccess)
                {
                    throw (Exception)Formatter.Deserialize(receiveStream);
                }
                return(responseHead.LeaveLength == 0 ? null : Formatter.Deserialize(receiveStream));

                #endregion
            }
            catch (Exception exception)
            {
                throw new Exception("无法连上指定通道!", exception);
            }
            finally
            {
                client?.Close();
            }
        }