Example #1
0
        /// <summary>
        ///     Start the HTTP server
        /// </summary>
        /// <param name="ipAddress">Address to listen on</param>
        /// <param name="port">Port to listen on.</param>
        /// <example>
        /// <p>You can load a certificate by doing the following:</p>
        /// <code>
        /// var certificate = new X509Certificate2(@"C:\certificates\yourCertificate", "yourpassword");
        /// var server = new HttpServer(new ModuleManager());
        /// server.Start(IPAddress.Any, 80, certifiate);
        /// </code>
        /// </example>
        public void Start(IPAddress ipAddress, int port, X509Certificate certifiate)
        {
            if (ipAddress == null)
            {
                throw new ArgumentNullException("ipAddress");
            }
            if (_listener != null)
            {
                throw new InvalidOperationException("Stop the server before restarting.");
            }

            var factory = new SecureTcpChannelFactory(new ServerSideSslStreamBuilder(certifiate));

            _listener = new HttpListener();
            _listener.ChannelFactory  = factory;
            _listener.MessageReceived = OnClientRequest;
            _listener.Start(ipAddress, port);
        }
        /// <summary>
        ///     Start the HTTP server
        /// </summary>
        /// <param name="ipAddress">Address to listen on</param>
        /// <param name="port">Port to listen on.</param>
        /// <example>
        /// <p>You can load a certificate by doing the following:</p>
        /// <code>
        /// var certificate = new X509Certificate2(@"C:\certificates\yourCertificate", "yourpassword");
        /// var server = new HttpServer(new ModuleManager());
        /// server.Start(IPAddress.Any, 80, certifiate);
        /// </code>
        /// </example>
        public void Start(IPAddress ipAddress, int port, X509Certificate certifiate)
        {
            if (ipAddress == null) throw new ArgumentNullException("ipAddress");
            if (_listener != null)
                throw new InvalidOperationException("Stop the server before restarting.");

            var factory=new SecureTcpChannelFactory(new ServerSideSslStreamBuilder(certifiate));
            _listener = new HttpListener();
            _listener.ChannelFactory = factory;
            _listener.MessageReceived = OnClientRequest;
            _listener.Start(ipAddress, port);
        }