RemoteClient1() { try { //Reachability.ServerSinkProvider.StartWaitRedirectedMsg(); remoteCommand = new RemoteCommand(); commandClient = new RemoteCommandClient(); commandClient.Sender = "WebAdminZ2"; commandClient.ReceiveCommandResultEvent += new ReceiveCommandResultEventHandler(client_ReceiveCommandResultEvent); commandClient.DeviceOfflineEvent += new DeviceOnlineOfflineEventHandler(client_DeviceOfflineEvent); commandClient.DeviceOnlineEvent += new DeviceOnlineOfflineEventHandler(client_DeviceOnlineEvent); commandClient.LogOffEvent += new EventHandler(commandClient_LogOffEvent); //ObjRef or = RemotingServices.Marshal(commandClient as MarshalByRefObject); if (!remoteCommand.AttachClient(commandClient)) { status = false; throw new Exception("登录失败,请查看日志!"); } else { status = true; } } catch (Exception ex) { status = false; //throw new Exception("连接服务器时出现异常,请重新尝试!异常信息" + ex.Message); } }
public bool ClientReAttach() { if (commandClient != null) { try { //RemotingServices.Disconnect(commandClient); } catch (Exception ex) { } } commandClient = new RemoteCommandClient(); commandClient.Sender = "WebAdminZ2"; commandClient.ReceiveCommandResultEvent += new ReceiveCommandResultEventHandler(client_ReceiveCommandResultEvent); commandClient.DeviceOfflineEvent += new DeviceOnlineOfflineEventHandler(client_DeviceOfflineEvent); commandClient.DeviceOnlineEvent += new DeviceOnlineOfflineEventHandler(client_DeviceOnlineEvent); commandClient.LogOffEvent += new EventHandler(commandClient_LogOffEvent); //ObjRef or = RemotingServices.Marshal(commandClient as MarshalByRefObject); if (!remoteCommand.AttachClient(commandClient)) { status = false; throw new Exception("重新自动连接失败!"); } else { status = true; } return(status); }
bool CreateCommandClient() { bool res = false; try { commandClient = new RemoteCommandClient(); commandClient.Sender = "WebAdminZ2"; commandClient.ReceiveCommandResultEvent += new ReceiveCommandResultEventHandler(client_ReceiveCommandResultEvent); commandClient.DeviceOfflineEvent += new DeviceOnlineOfflineEventHandler(client_DeviceOfflineEvent); commandClient.DeviceOnlineEvent += new DeviceOnlineOfflineEventHandler(client_DeviceOnlineEvent); commandClient.LogOffEvent += new EventHandler(commandClient_LogOffEvent); ObjRef or = RemotingServices.Marshal(commandClient as MarshalByRefObject); if (!remoteCommand.AttachClient(commandClient)) { res = false; } else { res = true; } } catch (Exception ex) { res = false; } return(res); }