/// <summary> /// Start the server. /// </summary> public void Start() { try { // Start the server. if (_httpServer != null) { _httpServer.Start(); } } catch (Exception) { if (_httpServer != null) { _httpServer.Dispose(); } _httpServer = null; throw; } }
/// <summary> /// Stop the server. /// </summary> public void Stop() { try { // Stop the server. if (_httpServer != null) { _httpServer.Stop(); } } catch { } finally { if (_httpServer != null) { _httpServer.Dispose(); } _httpServer = null; } }
/// <summary> /// Dispose(bool disposing) executes in two distinct scenarios. If disposing /// equals true, the method has been called directly or indirectly by a user's /// code. Managed and unmanaged resources can be disposed. If disposing equals /// false, the method has been called by the runtime from inside the finalizer /// and you should not reference other objects. Only unmanaged resources can /// be disposed. /// </summary> protected virtual void Dispose(bool disposing) { // Check to see if Dispose has already been called. if (!this._disposed) { // Note disposing has been done. _disposed = true; // If disposing equals true, dispose all managed // and unmanaged resources. if (disposing) { // Dispose managed resources. if (_httpServer != null) { _httpServer.Dispose(); } } // Call the appropriate methods to clean up // unmanaged resources here. _httpServer = null; } }
/// <summary> /// Initialise the server. /// </summary> private void Init() { try { // Create the server endpoint. Nequeo.Net.Sockets.MultiEndpointModel[] model = new Nequeo.Net.Sockets.MultiEndpointModel[] { // None secure. new Nequeo.Net.Sockets.MultiEndpointModel() { Port = Nequeo.Net.Properties.Settings.Default.HttpStaticServerListeningPort, Addresses = new System.Net.IPAddress[] { System.Net.IPAddress.IPv6Any, System.Net.IPAddress.Any } }, // Secure. new Nequeo.Net.Sockets.MultiEndpointModel() { Port = Nequeo.Net.Properties.Settings.Default.HttpStaticServerListeningPortSecure, Addresses = new System.Net.IPAddress[] { System.Net.IPAddress.IPv6Any, System.Net.IPAddress.Any } } }; // Start the server. _httpServer = new Nequeo.Net.Http.HttpServer(model); _httpServer.Name = "Application Server"; _httpServer.OnHttpContext += HttpContext; _httpServer.Timeout = 30; _httpServer.ReadBufferSize = 32768; _httpServer.WriteBufferSize = 32768; // Get the certificate reader. Nequeo.Security.Configuration.Reader certificateReader = new Nequeo.Security.Configuration.Reader(); // Inititalise. _httpServer.Initialisation(); try { // Look for the certificate information in the configuration file. // Get the certificate if any. X509Certificate2 serverCertificate = certificateReader.GetServerCredentials(); // If a certificate exists. if (serverCertificate != null) { // Get the secure servers. _httpServer.Server[2].UseSslConnection = true; _httpServer.Server[2].X509Certificate = serverCertificate; _httpServer.Server[3].UseSslConnection = true; _httpServer.Server[3].X509Certificate = serverCertificate; } } catch { } } catch (Exception) { if (_httpServer != null) { _httpServer.Dispose(); } _httpServer = null; throw; } }