コード例 #1
0
        public void RemoveObject(string variableName)
        {
            _dataObject = Variables.Find(x => x.Name == variableName);
            _dataObject.NotifyServerDisconnection();

            Variables.Remove(_dataObject);
        }
コード例 #2
0
        private void CreateNewRemotingObject(string variableName, Type t)
        {
            //服务器获取远程对象
            _dataObject = new RemotingObject(variableName, t);

            ObjRef objRef = RemotingServices.Marshal(_dataObject, _dataObject.Name);
        }
コード例 #3
0
ファイル: Client.cs プロジェクト: waylin15/Remoting
 private void Connect()
 {
     for (int i = 0; i < this.Retry; i++)
     {
         try
         {
             //获取代理
             _dataObject = (RemotingObject)Activator.GetObject(typeof(RemotingObject), string.Format("tcp://{0}:{1}/{2}", _config.ConnectedIP, _config.ConnectedPort, _config.Name));
             bool t = _dataObject == null;
             //订阅事件 (Remoting类库的限制,必须由另一个类库来执行客户端的事件)
             wrapper = new ClientEventWrapper();
             _dataObject.DataUpdatedEvent   += new RemotingObject.RemotingDelegate(wrapper.TriggerAtServerSwapEvent);
             wrapper.SwapSubscribeAtClient  += new RemotingObject.RemotingDelegate(OnDataReceiving);
             _dataObject.DisconnectNotifier += new RemotingObject.ServerDisconnectDelegate(wrapper.NotifyDisconnection);;
             wrapper.ServerDisconnect       += ServerDisconnect;
             this.Connected = true;
             return;
         }
         catch (Exception ex)
         {
             if (Marshal.GetHRForException(ex) == -2147467259)
             {
                 //-2147467259	由于目标计算机积极拒绝,无法连接。
                 continue;
             }
             else
             {
                 throw ex;
             }
         }
     }
     throw new Exception("连接失败,请检查连线配置");
 }