1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public partial class SaturnAPIService : ServiceBase
    {
        NancyHost host;
        public SaturnAPIService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            //necessary because of Namespace Reservations
            var config = new HostConfiguration() { RewriteLocalhost = true, UrlReservations = new UrlReservations() { CreateAutomatically = true } };

            host = new NancyHost(config, new Uri("http://localhost:1234"));
            
            host.Start();
            
        }

        protected override void OnStop()
        {
            host.Stop();
        }

refer to > https://github.com/NancyFx/Nancy/wiki/Self-Hosting-Nancy