Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var listeningOn = args.Length == 0 ? "http://*:1337/" : args[0];

            using (var appHost = new AppSelfHost())
            {
                try
                {
                    appHost.Init();
                    appHost.Start(listeningOn);

                    Console.WriteLine("AppHost Created at {0}, listening on {1}", DateTime.Now, listeningOn);
                    Console.WriteLine("Press <CTRL>+C to stop.");
                    Thread.Sleep(Timeout.Infinite);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("ERROR: {0}: {1}", ex.GetType().Name, ex.Message);
                    throw;
                }
                finally
                {
                    appHost.Stop();
                }
            }

            Console.WriteLine("AppHost has finished");
        }
        public static void StartListening(this AppSelfHost appHost, string urlBase)
        {
            var addedURLToACL = false;

            try
            {
                appHost.Start(urlBase);
            }
            catch (HttpListenerException ex)
            {
                if (IsMono())
                {
                    throw ex;
                }

                if (ex.ErrorCode == 5)
                {
                    AppHostSelfHelper.AddAddress(urlBase);
                    addedURLToACL = true;
                    appHost.Start(urlBase);
                }
            }

            Console.WriteLine("AppHost Created at {0}, listening on {1}", DateTime.Now, urlBase);
            Console.WriteLine("Press <Esc> to stop.");
            do
            {
            } while (Console.ReadKey(true).Key != ConsoleKey.Escape);

            if (addedURLToACL)
            {
                AppHostSelfHelper.DeleteAddress(urlBase);
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var listeningOn = args.Length == 0 ? "http://*:1337/" : args[0];

            using (var appHost = new AppSelfHost())
            {
                try
                {
                    appHost.Init();

                    // TODO: switch to Start after the next ServiceStack deployment (added to framework on commit #806)
                    appHost.StartListening(listeningOn);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("ERROR: {0}: {1}", ex.GetType().Name, ex.Message);
                }
                finally
                {
                    appHost.Stop();
                }
            }

            Console.WriteLine("AppHost has finished");
        }