I've hunted for the answer to this one, in SO and beyond but I've not seen any answers thus far.
We are looking at adding some reporting to an existing Windows Services / WPF EXE. Ideally we'd self-host a little vNext application that would expose reporting endpoints our app can use. This was possible with OWIN and ASP.NET 4.
Is this even possible with vNext?
I've tried a few samples etc and the K Runtime seems to, clearly, be a different runtime to the CLR. Build etc is all rather different too... so I guess at the very least it would have to be a completely separate process .... or am I barking up the wrong tree?
In particular it seems we need to invoke the K runtime (k web or elsed a k pack'ed .cmd) which seems coutner intuitive as I'm already within a process I'm running (the main exe/service).
EDIT: I'm wondering if the answer is NoWin , referenced and providing the OWIN container. B ut I'm struggling to see if that's the best approach...
Here a possible solution: How to Run DNX Applications in a Windows Service and How to Host ASP.NET in a Windows Service thanks to Erez Testiler.
Basically the idea is to add the following references:
And then programmatically configure and start the Server and ASP.NET:
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Hosting.Internal;
using Microsoft.Framework.Configuration;
using Microsoft.Framework.Configuration.Memory;
using Microsoft.Framework.DependencyInjection;
using System;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
....
private readonly IServiceProvider _serviceProvider;
private IHostingEngine _hostingEngine;
private IDisposable _shutdownServerDisposable;
public Program(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
protected override void OnStart(string[] args)
{
var configSource = new MemoryConfigurationSource();
configSource.Add("server.urls", "http://localhost:5000");
var config = new ConfigurationBuilder(configSource).Build();
var builder = new WebHostBuilder(_serviceProvider, config);
builder.UseServer("Microsoft.AspNet.Server.Kestrel");
builder.UseServices(services => services.AddMvc());
builder.UseStartup(appBuilder =>
{
appBuilder.UseDefaultFiles();
appBuilder.UseStaticFiles();
appBuilder.UseMvc();
});
_hostingEngine = builder.Build();
_shutdownServerDisposable = _hostingEngine.Start();
}
It seems to be a quite good solution to me.
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