I'm using OWIN to be able to serve static content over http from within a Windows Service. (To embed a Web Administration Tool for the Windows Service).
I experience some strange behaviour:
By the way, this files in this "web" folder are set to "Copy always" for the "Copy to Output Directory" property.
Anyone knows 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 that 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
}
}
I think I know what is going wrong: The 3rd party frameworks that you are using are either in alpha or beta. You should not rely on them based on you experience with them and their general state.
I created an almost identical setup (link to project files) and saw the exact same results. The used libraries are just not up to the task yet.
Edit:
I could get it to run much more relaibly with version 0.23.20815.0 of the Microsoft.Owin.StaticFiles library. I built it myself from the latest Katana sources. You can find my latest code at my GitHub page.
I use a similar configuration: Windows service as OWIN host with WebApi and StaticFiles. With this I did never see your problem. It's working fine.
I am using StaticFiles version 0.24.0-pre-20624-416 from the Katana Nightly Builds. Maybe this will solve also your problem. Another difference is, that I configure StaticFiles only with a relative path, not an absolute one as you do. It shouldn't make any difference, but who knows?
BTW: I blogged about StaticFiles 2 months ago: http://ritzlgrmft.blogspot.de/2013/06/owin-with-static-files-exception.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With