/// <summary> /// Overrides message calls and translates them to messages to remote application. /// </summary> /// <param name="msg">Method invoke message (from RealProxy base class)</param> /// <returns>Method invoke return message (to RealProxy base class)</returns> public override IMessage Invoke(IMessage msg) { if (_client.CommunicationState == CommunicationStates.Connected) { // If already connected, behave as base class (RemoteInvokeProxy). return(base.Invoke(msg)); } // Connect, call method and finally disconnect _client.Connect(); try { return(base.Invoke(msg)); } finally { _client.Disconnect(); } }
/// <summary> /// 将方法调用转换为远程方法调用 /// </summary> /// <param name="method">代理方法</param> /// <param name="parameters">代理参数</param> /// <returns>方法返回结果</returns> public override object Intercept(MethodInfo method, object[] parameters) { if (_client.CommunicationState == CommunicationStates.Connected) { //If already connected, behave as base class (RemoteInvokeProxy). return(base.Intercept(method, parameters)); } //Connect, call method and finally disconnect _client.Connect(); try { return(base.Intercept(method, parameters)); } finally { _client.Disconnect(); } }