private void StartService() { if (this._host != null) { this._host.Close(); this._host = null; } // Init the address Uri localAddress = new Uri(this._txtAddress.Text); WebHttpBinding binding = new WebHttpBinding(); this._clientsCount = 0; // Init the service this._service = new CcowParticipantService(); this._service.ClientConnected += new EventHandler <ClientConnectionEventArgs>(Service_ClientConnected); this._service.ClientDisconnected += new EventHandler <ClientConnectionEventArgs>(Service_ClientDisconnected); this._host = new ServiceHost(_service, localAddress); #if !DOTNET_2 binding.CrossDomainScriptAccessEnabled = true; #endif // DOTNET_2 ServiceEndpoint endpoint = _host.AddServiceEndpoint(typeof(ICcowParticipantService), binding, localAddress); // Add cors support (for Cross Domain) endpoint.Behaviors.Add(new CorsSupportBehavior()); // Add CcowWebHttpBehavior for parameters conversion endpoint.Behaviors.Add(new CcowWebHttpBehavior()); this._host.Open(); }
private void MainForm_FormClosed(object sender, FormClosedEventArgs e) { // Close the host if (_host != null) { _host.Close(); _host = null; _service = null; } this._trayIcon.Visible = false; }