public PrinterService()
        {
            InitializeComponent();

            config = new HttpSelfHostConfiguration(AppConfig.BaseUrl);
            config.MapHttpAttributeRoutes();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The program main method
        /// </summary>
        /// <param name="args">The program arguments</param>
        private static void Main(string[] args)
        {
            var config = new HttpSelfHostConfiguration(ServiceAddress);

            config.MapHttpAttributeRoutes();
            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
            config.EnableCors(new EnableCorsAttribute("*", "*", "*"));

            using (var server = new HttpSelfHostServer(config)) {
                try {
                    server.OpenAsync().Wait();
                    Console.WriteLine("Service running on " + ServiceAddress + ". Press enter to quit.");
                    Console.ReadLine();
                }
                catch (Exception e) {
                    if (!IsAdministrator()) {
                        Console.WriteLine("Please restart as admin.");
                        Debug.WriteLine("Restart Visual Studio as admin");
                    }
                    else {
                        Console.WriteLine("Server failed to start.");
                    }
                    Console.ReadLine();
                }
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var address = "http://localhost:900";
            var config = new HttpSelfHostConfiguration(address);
            config.MapHttpAttributeRoutes();

            using (var server = new HttpSelfHostServer(config))
            {
                server.OpenAsync().Wait();
                Console.WriteLine("Server running at {0}. Press any key to exit", address);

                var client = new HttpClient() {BaseAddress = new Uri(address)};

                var persons = client.GetAsync("person").Result;
                Console.WriteLine(persons.Content.ReadAsStringAsync().Result);

                var newPerson = new Person {Id = 3, Name = "Luiz"};
                var response = client.PostAsJsonAsync("person", newPerson).Result;

                if (response.IsSuccessStatusCode)
                {
                    var person3 = client.GetAsync("person/3").Result;
                    Console.WriteLine(person3.Content.ReadAsStringAsync().Result);
                }

                Console.ReadLine();
            }

        }
 static void Main(string[] args)
 {
     HttpSelfHostConfiguration configuration = new HttpSelfHostConfiguration("http://localhost:3721");
     configuration.MapHttpAttributeRoutes();
     HttpSelfHostServer server = new HttpSelfHostServer(configuration);
     server.OpenAsync().Wait();
     Console.Read();
 }
Ejemplo n.º 5
0
        private static void Main()
        {
            const string address = "http://localhost:925/";

            var config = new HttpSelfHostConfiguration(address);
            config.MapHttpAttributeRoutes();
            var handler = new HawkMessageHandler(
                async id => new HawkCredential
                {
                    Id = id,
                    Key = "abcdefghijkl",
                    Algorithm = "sha256",
                    User = "******"
                }, 4, true);

            config.MessageHandlers.Add(handler);

            using (var server = new HttpSelfHostServer(config))
            {
                server.OpenAsync().Wait();
                var client = new HttpClient();

                //this will fail
                var request = new HttpRequestMessage(HttpMethod.Get, address + "test");
                var response = client.SendAsync(request).Result;
                Console.WriteLine(response.StatusCode);
                Console.WriteLine();

                var credential = new HawkCredential
                {
                    Id = "this-is-my-id",
                    Key = "abcdefghijkl",
                    Algorithm = "sha256",
                    User = "******"
                };

                var clientHandler = new HawkClientMessageHandler(new HttpClientHandler(), credential, ts: DateTime.Now);
                var client2 = new HttpClient(clientHandler);

                //this will succeed
                request = new HttpRequestMessage(HttpMethod.Get, address + "test");
                var response2 = client2.SendAsync(request).Result;
                Console.WriteLine(response2.StatusCode);
                Console.WriteLine(response2.Content.ReadAsStringAsync().Result);
                Console.WriteLine();

                Console.WriteLine("Sleeping to get outside of the timestamp window. Next request will fail - replay protection.");
                Thread.Sleep(5000);

                //this will fail
                request = new HttpRequestMessage(HttpMethod.Get, address + "test");
                var response3 = client2.SendAsync(request).Result;
                Console.WriteLine(response3.StatusCode);
                Console.WriteLine();

                Console.ReadLine();
            }
        }
Ejemplo n.º 6
0
        public MediaStreamingServer(int port = 8080)
        {
            Address = "http://" + Ext.GetIp4Address() + ":" + port;
            var config = new HttpSelfHostConfiguration(Address);
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new {id = RouteParameter.Optional}
                );
            config.TransferMode = TransferMode.Streamed;
            httpSelfHostServer = new HttpSelfHostServer(config);
        }
Ejemplo n.º 7
0
 protected override void OnStart(string[] args)
 {
     var selfHostConfiguraiton = new HttpSelfHostConfiguration("http://localhost:9999/");
     selfHostConfiguraiton.Routes.MapHttpRoute(
         name: "ApiRoute",
         routeTemplate: "api/{controller}",
         defaults: null
     );
     selfHostConfiguraiton.MapHttpAttributeRoutes();
     selfHostConfiguraiton.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
     _webApiServer = new HttpSelfHostServer(selfHostConfiguraiton);
     _webApiServer.OpenAsync().Wait();
 }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            var baseAddress = "http://localhost:8080";
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(baseAddress);

            // config.MessageHandlers.Add(new ProgressMessageHandler() { });


            // Web API 路由
            config.MapHttpAttributeRoutes();

            //全局允许CROS
            // config.EnableCors();//启用跨域


            config.Routes.MapHttpRoute
            (
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
            config.MaxConcurrentRequests = 1000;
            var handlers      = new DelegatingHandler[] { new PassiveAuthenticationMessageHandler(), new HttpServer() };
            var routeHandlers = HttpClientFactory.CreatePipeline(new HttpControllerDispatcher(config), handlers);

            config.Routes.MapHttpRoute(
                name: "CustomerRouter",
                routeTemplate: "MyAPI/{Controller}/{Action}/Id",
                defaults: new { Id = RouteParameter.Optional },
                constraints: null,
                handler: routeHandlers
                );
            HttpSelfHostServer server = new HttpSelfHostServer(config);

            server.OpenAsync();


            TaskManager.Instance.Initialize();
            TaskManager.Instance.Start();
            DefaultHttpBatchHandler batchHandler = new DefaultHttpBatchHandler(server);

            Console.WriteLine("Server  http://localhost:8080   Open now ....at {0}..", server.Configuration.VirtualPathRoot);
            config.EnsureInitialized();
            foreach (var route in config.Routes)
            {
                System.Diagnostics.Debug.WriteLine(route);
            }

            Console.ReadLine();
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {

            var baseAddress = "http://localhost:8080";
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(baseAddress);
           // config.MessageHandlers.Add(new ProgressMessageHandler() { });


            // Web API 路由
            config.MapHttpAttributeRoutes();

            //全局允许CROS
            // config.EnableCors();//启用跨域


            config.Routes.MapHttpRoute
           (
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional }
            );
            config.MaxConcurrentRequests = 1000;
            var handlers = new DelegatingHandler[] { new PassiveAuthenticationMessageHandler(), new HttpServer() };
            var routeHandlers = HttpClientFactory.CreatePipeline(new HttpControllerDispatcher(config), handlers);
            config.Routes.MapHttpRoute(
                   name: "CustomerRouter",
                  routeTemplate: "MyAPI/{Controller}/{Action}/Id",
                  defaults: new { Id = RouteParameter.Optional },
                  constraints: null,
                  handler: routeHandlers
                );
            HttpSelfHostServer server = new HttpSelfHostServer(config);
            server.OpenAsync();


            TaskManager.Instance.Initialize();
            TaskManager.Instance.Start();
           DefaultHttpBatchHandler batchHandler = new DefaultHttpBatchHandler(server);

            Console.WriteLine("Server  http://localhost:8080   Open now ....at {0}..", server.Configuration.VirtualPathRoot);
            config.EnsureInitialized();
            foreach (var route in config.Routes)
            {
                System.Diagnostics.Debug.WriteLine(route);
            }

            Console.ReadLine();

        }
Ejemplo n.º 10
0
        public Service()
        {
            var selfHostConfiguraiton = new HttpSelfHostConfiguration("http://localhost:5555");

            selfHostConfiguraiton.MapHttpAttributeRoutes();

            selfHostConfiguraiton.MapODataServiceRoute("api", "api", GetApiModel());

            selfHostConfiguraiton.Routes.MapHttpRoute(
                name: "DefaultApiRoute",
                routeTemplate: "{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            server = new HttpSelfHostServer(selfHostConfiguraiton);
        }
        void SetUp()
        {
            Injector.Resolver = new TestResolver();
            var endpoint = "http://localhost:40000";

            target = new RemoteDecisionService(endpoint);
            var config = new HttpSelfHostConfiguration(endpoint);

            config.DependencyResolver = new InjectorDependencyResolver();

            // Decision routes
            config.MapHttpAttributeRoutes();

            server = new HttpSelfHostServer(config);
            server.OpenAsync().Wait();
        }
Ejemplo n.º 12
0
        public Uri Start(string serviceName, string version)
        {
            var uri = Configuration.GetUri();
            var config = new HttpSelfHostConfiguration(uri);

            // Attribute routing.
            config.MapHttpAttributeRoutes();

            // Convention-based routing.
            config.Routes.MapHttpRoute(
                "API Default", "{controller}/{id}",
                new { id = RouteParameter.Optional });

            var server = new HttpSelfHostServer(config);
            server.OpenAsync().Wait();
            return uri;
        }
Ejemplo n.º 13
0
        public void Start()
        {
            var nodeConfigString = File.ReadAllText("config.json");
            var settings = new Newtonsoft.Json.JsonSerializerSettings
            {
                TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Auto,
            };
            var config = Newtonsoft.Json.JsonConvert.DeserializeObject<JSONConfig>(nodeConfigString, settings);

            // config Syslog listener
            if (config.syslog.listenerEnabled)
            {
                var listener = new SyslogListener();
                Action<int> startListener = listener.Start;
                startListener.BeginInvoke(config.syslog.listenerPort, null, null);
            }

            // config PollEngine
            foreach (var node in (config.nodes ?? new JSONConfigNode[0]))
            {
                var pollNode = Activator.CreateInstance(typeof(PollingEngine).Assembly.GetType(node.type), new object[] { node.name, node.groups ?? new string[0], node.settings }) as PollNode;
                PollingEngine.TryAdd(pollNode);
            }
            PollingEngine.StartPolling();

            // config HTTP API
            var hostConfig = new HttpSelfHostConfiguration("http://127.0.0.1:" + config.http.listenerPort);
            // Remove the XML formatter
            hostConfig.Formatters.Remove(hostConfig.Formatters.XmlFormatter);
            hostConfig.Formatters.Add(new RazorFormatter());
            hostConfig.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Auto;
            hostConfig.Formatters.JsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
            hostConfig.Formatters.JsonFormatter.SerializerSettings.Error += (x, y) =>
            {
                return;
            };
            hostConfig.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("type", "json", new MediaTypeHeaderValue("application/json")));
            // Attribute routing.
            hostConfig.MapHttpAttributeRoutes();
            hostConfig.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
            hostConfig.Filters.Add(new ApiExceptionFilterAttribute());

            httpServer = new HttpSelfHostServer(hostConfig);
            httpServer.OpenAsync().Wait();
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            var config = new HttpSelfHostConfiguration("http://localhost:999");
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(
                  name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
            var server = new HttpSelfHostServer(config);

            config.CacheOutputConfiguration().RegisterCacheOutputProvider(() => new MemoryCacheDefault());

            server.OpenAsync().Wait();

            Console.ReadKey();

            server.CloseAsync().Wait();
        }
Ejemplo n.º 15
0
        private static async Task <HttpSelfHostServer> CreateServerAsync(PortReserver port, TransferMode transferMode, bool ignoreRoute = false)
        {
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(BaseUri(port, transferMode));

            config.HostNameComparisonMode = HostNameComparisonMode.Exact;
            if (ignoreRoute)
            {
                config.Routes.IgnoreRoute("Ignore", "{controller}/{action}");
                config.Routes.IgnoreRoute("IgnoreWithConstraints", "constraint/values/{id}", constraints: new { constraint = new CustomConstraint() });
            }
            config.Routes.MapHttpRoute("Default", "{controller}/{action}");
            config.Routes.MapHttpRoute("Other", "other/{controller}/{action}");
            config.TransferMode = transferMode;
            config.MapHttpAttributeRoutes();

            HttpSelfHostServer server = new HttpSelfHostServer(config);
            await server.OpenAsync();

            return(server);
        }
Ejemplo n.º 16
0
        private static async Task StartAsync()
        {
            var serviceUri = "http://localhost:9000";
            var httpConfig = new HttpSelfHostConfiguration(serviceUri);
            httpConfig.MapHttpAttributeRoutes();

            s_httpServer = new HttpSelfHostServer(httpConfig);
            try
            {
                await s_httpServer.OpenAsync();
            }
            catch (System.ServiceModel.AddressAccessDeniedException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("");
                Console.WriteLine("type following command in administrative commandline to runs this program");
                Console.WriteLine("> netsh http add urlacl http://+:9000/ user=Everyone");
                Console.WriteLine("");
            }
        }
Ejemplo n.º 17
0
        public Service()
        {
            var selfHostConfiguraiton = new HttpSelfHostConfiguration("http://localhost:5555");

            selfHostConfiguraiton.MapHttpAttributeRoutes();

            selfHostConfiguraiton.Routes.MapHttpRoute(
                name: "DefaultApiRoute",
                routeTemplate: "api/{controller}",
                defaults: null
                );

            selfHostConfiguraiton.Routes.MapHttpRoute(
                name: "ApiRouteWithAction",
                routeTemplate: "api/{controller}/{action}",
                defaults: null
                );

            server = new HttpSelfHostServer(selfHostConfiguraiton);
        }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            var addr = "http://localhost:925";
            var config = new HttpSelfHostConfiguration(addr)
            {
                ClientCredentialType = HttpClientCredentialType.Windows
            };
            config.MapHttpAttributeRoutes();

            using (var server = new HttpSelfHostServer(config))
            {
                server.OpenAsync().Wait();


                var client = new HttpClient(new HttpClientHandler {UseDefaultCredentials = true});
                var result = client.GetAsync(addr + "/test").Result;
                Console.WriteLine(result.StatusCode);
                Console.WriteLine(result.Content.ReadAsStringAsync().Result);

                Console.ReadLine();
            }
        }
Ejemplo n.º 19
0
        static HttpSelfHostServer ConfigureServer(string serverUrl)
        {
            // set up the server side
            var config = new HttpSelfHostConfiguration(serverUrl);
            // Attribute routing
            config.MapHttpAttributeRoutes();

            // Convention-based routing
            config.Routes.MapHttpRoute(
                "API Default", "api/{controller}/{id}",
                new { id = RouteParameter.Optional });

            // set the default WebAPI format to JSON
            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));

            // enable Cross Origin Resource Sharing
            config.EnableCors();

            return new HttpSelfHostServer(config);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 配置服务路由
        /// </summary>
        /// <param name="configuration"></param>
        private static void SetRoutes(HttpSelfHostConfiguration configuration)
        {
            configuration.MapHttpAttributeRoutes();

            configuration.Routes.MapHttpRoute(
                    name: "CollectionStatus",
                    routeTemplate: "api/CollectionStatus/{serviceName}",
                    defaults: new
                    {
                        controller = "CollectionStatus",
                        serviceName = RouteParameter.Optional
                    }
                );

            configuration.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{stockCode}",
                defaults: new
                {
                    stockCode = RouteParameter.Optional
                }
            );
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Call SelfHost Https Service
        /// </summary>
        /// <returns>Awaitable task object</returns>
        private async static Task CallSelfHostHttpsService()
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Start processing Self-Host Https service operation call");

            try
            {
                // Set up SelfHost configuration
                HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(serverDefaultSecureURL);

                config.MapHttpAttributeRoutes();

                config.Routes.MapHttpRoute(
                    name: "SelfHostActionApi",
                    routeTemplate: "{controller}/{action}/{id}",
                    defaults: new { id = RouteParameter.Optional }
                );

                config.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling = TypeNameHandling.Auto;

                // Create server
                using (HttpSelfHostServer server = new HttpSelfHostServer(config))
                {
                    // Open server
                    server.OpenAsync().Wait();
                    Console.WriteLine(string.Concat("Opening server ", serverDefaultSecureURL));
                    Console.WriteLine();

                    // In order to communicate with server,need to validate remote server certificate 
                    ServicePointManager.ServerCertificateValidationCallback +=
                        new RemoteCertificateValidationCallback(ValidateRemoteCertificate);

                    Uri address = new Uri(serverDefaultSecureURL, "physicianselfhost/calculatesalaryraise");
                    await ProcessRaiseSalaryRequest(address);

                    server.CloseAsync().Wait();
                }
            }
            catch (Exception exception)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(exception);
            }
        }
        private static HttpSelfHostServer CreateServer(PortReserver port, TransferMode transferMode, bool ignoreRoute = false)
        {
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(BaseUri(port, transferMode));
            config.HostNameComparisonMode = HostNameComparisonMode.Exact;
            if (ignoreRoute)
            {
                config.Routes.IgnoreRoute("Ignore", "{controller}/{action}");
                config.Routes.IgnoreRoute("IgnoreWithConstraints", "constraint/values/{id}", constraints: new { constraint = new CustomConstraint() });
            }
            config.Routes.MapHttpRoute("Default", "{controller}/{action}");
            config.Routes.MapHttpRoute("Other", "other/{controller}/{action}");
            config.TransferMode = transferMode;
            config.MapHttpAttributeRoutes();

            HttpSelfHostServer server = new HttpSelfHostServer(config);
            server.OpenAsync().Wait();
            return server;
        }
Ejemplo n.º 23
0
        protected override void OnStart(string[] args)
        {
            Uri baseAddress = new Uri("http://" + ConfigurationManager.AppSettings["server"] + GetPort());
            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(baseAddress)
            {
                HostNameComparisonMode = HostNameComparisonMode.Exact
            };

            string origins = ConfigurationManager.AppSettings["corsItems"];
            if (string.IsNullOrEmpty(origins))
            {
                origins = "*";
            }
            config.EnableCors(new EnableCorsAttribute(origins, "*", "*"));

            var formatters = GlobalConfiguration.Configuration.Formatters;
            formatters.Remove(formatters.XmlFormatter);

            WebApiConfig.Register(config);
            config.MapHttpAttributeRoutes();
            config.EnsureInitialized();

            _server = new HttpSelfHostServer(config);
            // Start listening
            _server.OpenAsync().Wait();
            System.Console.WriteLine("Listening on " + baseAddress);
        }
Ejemplo n.º 24
0
        private async Task StartHttp()
        {
            var baseAddress = new Uri($"http://localhost:{PortSetting}/");
            try
            {
                // Set up server configuration
                var config = new HttpSelfHostConfiguration(baseAddress);
                // config.Services.Replace(typeof(ITraceWriter), new SimpleTracer());

                //Add our way too simple Authentication 
                config.Filters.Add(new ZvsAuthenticatioFilter(this));

                // Web API routes
                config.MapHttpAttributeRoutes();

                var resolver = new WebApi2PluginDependencyResolver(this);
                config.DependencyResolver = resolver;

                config.EnableCors(new EnableCorsAttribute("*", "*", "*"));

                //config.Routes.MapHttpRoute(
                //    name: "DefaultApi",
                //    routeTemplate: "api/{controller}/{id}",
                //    defaults: new { id = RouteParameter.Optional }
                //);

                var builder = new ODataConventionModelBuilder();
                
                var scheduledTaskType = builder.EntityType<ScheduledTask>();
                scheduledTaskType.Ignore(t => t.StartTime);
                scheduledTaskType.Property(t => t.StartTimeOffset).Name = "StartTime";

                var deviceValueHistoryTaskType = builder.EntityType<DeviceValueHistory>();
                deviceValueHistoryTaskType.Ignore(t => t.DateTime);
                deviceValueHistoryTaskType.Property(t => t.DateTimeOffset).Name = "DateTime";
                
                var logEntryType = builder.EntityType<LogEntry>();
                logEntryType.Ignore(t => t.Datetime);
                logEntryType.Property(t => t.DateTimeOffset).Name = "Datetime";

                builder.EntitySet<Command>("Commands");
                var cExecute = builder.EntityType<Command>().Action("Execute");
                cExecute.Parameter<string>("Argument");
                cExecute.Parameter<string>("Argument2");


                builder.EntitySet<BuiltinCommand>("BuiltinCommands");
                builder.EntitySet<Device>("Devices");
                builder.EntitySet<DeviceCommand>("DeviceCommands");
                builder.EntitySet<DeviceTypeCommand>("DeviceTypeCommands");
                builder.EntitySet<DeviceValueTrigger>("DeviceValueTriggers");
                builder.EntitySet<DeviceValue>("DeviceValues");
                builder.EntitySet<DeviceValueHistory>("DeviceValueHistories");
                builder.EntitySet<Group>("Groups");
                builder.EntitySet<Scene>("Scenes");
                builder.EntitySet<SceneStoredCommand>("SceneStoredCommands");
                builder.EntitySet<ScheduledTask>("ScheduledTasks");
                builder.EntitySet<LogEntry>("LogEntries");
                builder.Namespace = "Actions";
                config.MapODataServiceRoute("ODataRoute", "odata4", builder.GetEdmModel());

                //config.MapODataServiceRoute(
                //routeName: "ODataRoute",
                //routePrefix: null,
                //model: builder.GetEdmModel());

                // Create server
                HttpSelfHostServer = new HttpSelfHostServer(config);

                // Start listening
                await HttpSelfHostServer.OpenAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not start server: {0}", e.GetBaseException().Message);
            }

            await Log.ReportInfoFormatAsync(CancellationToken, "WebApi2 Server Online on port {0} {1} SSL", baseAddress, UseSslSetting ? "using" : "not using");
        }
Ejemplo n.º 25
-1
        public static void Main(string[] args)
        {
            var config = new HttpSelfHostConfiguration("http://127.0.0.1:3001");

            config.MapHttpAttributeRoutes();
            config.EnableCors();
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            config.Routes.MapHttpRoute(
                name: "ReportsApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));

            using (HttpSelfHostServer server = new HttpSelfHostServer(config))
            {
                server.OpenAsync().Wait();
                Console.WriteLine("Press Enter to quit.");
                Console.ReadLine();
            }
        }