private void InitComm(string clientname, string pluginname) { if (string.IsNullOrEmpty(clientname)) { clientname = getLocalIPAddress(); } if (string.IsNullOrEmpty(pluginname)) { pluginname = "SuperPlugin"; } mConn = new CHDEPConnection(); mConn.ClientName = clientname; mConn.RouterID = Guid.NewGuid().ToString(); mConn.PluginName = pluginname; mConn.ClientService = new ReplyClientCallBack(); if (mChannelFactory == null) { mChannelFactory = new DuplexChannelFactory <IWCFHandlerService>(mConn.ClientService, "wcfendpoint"); } if (mfileChannelFactory == null) { mfileChannelFactory = new ChannelFactory <IFileTransfer>("fileendpoint"); } }
/// <summary> /// 卸载连接 /// </summary> public void UnConnection() { if (mConn == null) { return; } string mClientID = mConn.ClientID; IWCFHandlerService mWcfService = mConn.WcfService; if (mClientID != null) { try { AddMessageHeader(mWcfService as IContextChannel, "Quit", (() => { mWcfService.UnDomain(mClientID); })); //mChannelFactory.Close();//关闭通道 (mWcfService as IContextChannel).Close(); if (timer != null)//关闭连接必须停止心跳 { timer.Stop(); } } catch { if ((mWcfService as IContextChannel) != null) { (mWcfService as IContextChannel).Abort(); } } mConn = null; } }