/// <remarks> /// If you start any asynchronous methods here, prevent the task /// from closing prematurely by using BackgroundTaskDeferral as /// described in http://aka.ms/backgroundtaskdeferral /// </remarks> public async void Run(IBackgroundTaskInstance taskInstance) { // This deferral should have an instance reference, if it doesn't... the GC will // come some day, see that this method is not active anymore and the local variable // should be removed. Which results in the application being closed. _deferral = taskInstance.GetDeferral(); var restRouteHandler = new RestRouteHandler(); restRouteHandler.RegisterController<AsyncControllerSample>(); restRouteHandler.RegisterController<FromContentControllerSample>(); restRouteHandler.RegisterController<PerCallControllerSample>(); restRouteHandler.RegisterController<SimpleParameterControllerSample>(); restRouteHandler.RegisterController<SingletonControllerSample>(); restRouteHandler.RegisterController<ThrowExceptionControllerSample>(); restRouteHandler.RegisterController<WithResponseContentControllerSample>(); var configuration = new HttpServerConfiguration() .ListenOnPort(8800) .RegisterRoute("api", restRouteHandler) .RegisterRoute(new StaticFileRouteHandler(@"Restup.DemoStaticFiles\Web")) .EnableCors(); // allow cors requests on all origins // .EnableCors(x => x.AddAllowedOrigin("http://specificserver:<listen-port>")); var httpServer = new HttpServer(configuration); _httpServer = httpServer; await httpServer.StartServerAsync(); // Dont release deferral, otherwise app will stop }
private async Task InitializeWebServer() { var restRouteHandler = new RestRouteHandler(); restRouteHandler.RegisterController<AsyncControllerSample>(); restRouteHandler.RegisterController<FromContentControllerSample>(); restRouteHandler.RegisterController<PerCallControllerSample>(); restRouteHandler.RegisterController<SimpleParameterControllerSample>(); restRouteHandler.RegisterController<SingletonControllerSample>(); restRouteHandler.RegisterController<ThrowExceptionControllerSample>(); restRouteHandler.RegisterController<WithResponseContentControllerSample>(); var configuration = new HttpServerConfiguration() .ListenOnPort(8800) .RegisterRoute("api", restRouteHandler) .RegisterRoute(new StaticFileRouteHandler(@"Restup.DemoStaticFiles\Web")) .EnableCors(); // allow cors requests on all origins //.EnableCors(x => x.AddAllowedOrigin("http://specificserver:<listen-port>")); var httpServer = new HttpServer(configuration); _httpServer = httpServer; await httpServer.StartServerAsync(); // Don't release deferral, otherwise app will stop }