//初始化 public bool Init() { lock (this) { try { transport = new TSocket(m_host, m_port, m_timeout); protocol = new TBinaryProtocol(transport); TMultiplexedProtocol mp = new TMultiplexedProtocol(protocol, "SercurityService"); SercurityClient = new SercurityService.Client(mp); TMultiplexedProtocol mp2 = new TMultiplexedProtocol(protocol, "SaleService"); SaleClient = new SaleService.Client(mp2); TMultiplexedProtocol mp3 = new TMultiplexedProtocol(protocol, "DataSyncService"); DataSyncClient = new DataSyncService.Client(mp3); if (transport != null && !transport.IsOpen) { transport.Open(); } return(true); } catch (Exception ex) { if (transport != null) { transport.Dispose(); } if (protocol != null) { protocol.Dispose(); } if (DataSyncClient != null) { DataSyncClient.Dispose(); } if (SaleClient != null) { SaleClient.Dispose(); } if (SercurityClient != null) { SercurityClient.Dispose(); } if (SystemClient != null) { SystemClient.Dispose(); } transport = null; protocol = null; SercurityClient = null; SystemClient = null; SaleClient = null; DataSyncClient = null; _log.Error(ex.Message.ToString()); return(false); } } }
//释放链接 public void Dispose() { lock (this) { try { if (transport != null && transport.IsOpen) { transport.Close(); } if (transport != null) { transport.Dispose(); } if (protocol != null) { protocol.Dispose(); } if (DataSyncClient != null) { DataSyncClient.Dispose(); } if (SaleClient != null) { SaleClient.Dispose(); } if (SercurityClient != null) { SercurityClient.Dispose(); } if (SystemClient != null) { SystemClient.Dispose(); } transport = null; protocol = null; SercurityClient = null; SystemClient = null; SaleClient = null; DataSyncClient = null; } catch (Exception ex) { throw new Exception(ex.Message.ToString()); } } }