I am using OWIN to serve static content via http from a windows service. (To integrate the web administration tool for the Windows service).
I experience strange behavior:
- When the service starts, I can access only one file located in the "web" folder, each successive call leads to the browser indicating that the page is inaccessible (ERR_CONNECTION_RESET).
- Embedded WebApi remains available .
- When I restart the service with the same address and port, the files remain invisible.
- When I restart the service on another port, I can access the file once ...
By the way, these files in this "Internet" folder are set to "Always copy" for the "Copy to output directory" property.
Does anyone know what is going wrong?
See here my StartUp configuration class
public class WebStartUp { public void Configuration(IAppBuilder app) { string staticFilesDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "web"); app.UseStaticFiles(staticFilesDir); HttpConfiguration config = new HttpConfiguration(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); app.UseWebApi(config); } }
See here my windows service which hosts it ...
public partial class MyService : ServiceBase { private IDisposable webApp; private const string ServiceAddress = "http://localhost:2345"; public MyService() { } protected override void OnStart(string[] args) { InternalStart(); } internal void InternalStart() { webApp = WebApp.Start<WebStartUp>(url: ServiceAddress); } protected override void OnStop() { } public static void Main() { #if DEBUG var service = new MyService(); Console.WriteLine("starting"); service.InternalStart(); Console.ReadLine(); #else ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new RaceManagerService(); } ServiceBase.Run(ServicesToRun); #endif } }
source share