public IEarthNamedpipeService CreateChannel(string address) { try { NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None); binding.MaxBufferPoolSize = cMaxBuffer; binding.MaxBufferSize = cMaxBuffer; binding.MaxReceivedMessageSize = cMaxBuffer; binding.ReceiveTimeout = TimeSpan.MaxValue; ServiceEndpoint se = new ServiceEndpoint( ContractDescription.GetContract(typeof(IEarthNamedpipeService)), binding, new EndpointAddress(address)); _factory = new ChannelFactory <IEarthNamedpipeService>(se); IEarthNamedpipeService channel = _factory.CreateChannel(); return(channel); } catch { Console.WriteLine(cConnectError); return(null); } }
public void CloseConnect() { if (_factory != null) { _factory.Close(); _factory = null; } _channel = null; }
public async Task <string> Connect(string exePath = null) { try { string address = null; ProcessUtils proc = new ProcessUtils(c_processName, exePath); if (!proc.IsRunning()) { await proc.Start((msg) => ProcessStdOutCallBack(msg, ref address)); if (String.IsNullOrEmpty(address)) { return(cFailed); } } else { address = cBasePipeAddress; } if (!String.IsNullOrEmpty(address)) { _channel = CreateChannel(address); // call a function to test consistency of contract file. string test = _channel.GetCameraJson(); if (_channel != null) { return(cSuccess); } else { return(cFailed); } } return(cFailed); } catch { _channel = null; return(cFailed); } }
public bool Connect() { try { _channel = CreateChannel(cBasePipeAddress); // call a function to test consistency of contract file. string test = _channel.GetCameraJson(); if (_channel != null) { return(true); } else { _channel = null; return(false); } } catch { return(false); } }