public static void Start() { if (crs == null && customResolver == null) { crs = new CustomPeerResolverService(); crs.ControlShape = false; customResolver = new ServiceHost(crs); crs.Open(); customResolver.BeginOpen((AsyncCallback)((t) => { App.Log.Info("Служба разрешения имен запущена успешно!"); App.ViewModel.AddLogMessage("Служба разрешения имен запущена успешно!"); }), null);//.Open(); } }
public static void Main() { // Create a new resolver service CustomPeerResolverService crs = new CustomPeerResolverService(); crs.ControlShape = false; // Create a new service host ServiceHost customResolver = new ServiceHost(crs); // Open the resolver service crs.Open(); customResolver.Open(); Console.WriteLine("Custom resolver service is started"); Console.WriteLine("Press <ENTER> to terminate service"); Console.ReadLine(); }
private void btnStart_Click(object sender, EventArgs e) { try { cprs = new CustomPeerResolverService(); cprs.RefreshInterval = TimeSpan.FromSeconds(5); host = new ServiceHost(cprs); cprs.ControlShape = true; cprs.Open(); host.Open(TimeSpan.FromDays(1000000)); lblMessage.Text = "Serwer zosta³ uruchomiony."; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { btnStartServer.Enabled = false; btnStopServer.Enabled = true; } }
private void btnStart_Click(object sender, EventArgs e) { try { Binding bind = new NetPeerTcpBinding(); cprs = new CustomPeerResolverService(); cprs.RefreshInterval = TimeSpan.FromSeconds(5); host = new ServiceHost(cprs, new Uri[] { new Uri("net.tcp://127.0.0.1/ChatServer") }); cprs.ControlShape = true; cprs.Open(); host.Open(TimeSpan.FromDays(1000000)); lblMessage.Text = "Server started successfully."; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { btnStart.Enabled = false; btnStop.Enabled = true; } }
static void Main(string[] args) { List<ServiceHost> hosts = new List<ServiceHost>(); ServiceHost host1 = new ServiceHost(typeof(RegisterService)); ServiceHost host2 = new ServiceHost(typeof(ChatterService)); cprs = new CustomPeerResolverService(); cprs.RefreshInterval = TimeSpan.FromSeconds(5); cprs.ControlShape = true; cprs.Open(); ServiceHost host3 = new ServiceHost(cprs); hosts.Add(host1); hosts.Add(host2); hosts.Add(host3); Console.WriteLine("***************输入\"exit\" 关闭程序***************"); Console.WriteLine(); foreach (ServiceHost host in hosts) { host.Opened += delegate { ; MyLogger.Logger.Info(host.Description.Name + "已经启动"); }; host.Closed += delegate { MyLogger.Logger.Info(host.Description.Name + "已经关闭"); }; host.Open(); } string s = String.Empty; while (true) { s = Console.ReadLine(); if (s.Trim().ToLower() == "exit") { break; } else if (s.Trim().ToLower() == "clear") { Console.Clear(); } } ChatterService.isAlive = false; foreach (ServiceHost host in hosts) { host.Close(); } }