Reputation: 2858
Typically a WPF application is a consumer/client of a RESTful service(s) on a web server. I would like to have it reversed - WPF application should be able to expose an web API. This would be consumed by an web app.
The flow:
web app ---sends a command to--> WPF app
** WPF app makes a 'long running job' until its user decides to stop **
WPF app ---passes data back to--> web app
The communication should be in Json format. I have prepared OpenAPI (in YAML) schema for it at the http://editor.swagger.io/. In the future it could be used to make changes to the WPF app's web API.
It allows to generate ASP.NET Core server c# code stub. What would be the requirements to run ASP.NET Core server in WPF and weither it would be light weight enough for use?
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
// somewhere in the WPF app: BuildWebHost(args).Run();
The code is auto-generated by https://github.com/swagger-api/swagger-codegen.
There is a post which failed to integrate ASP.NET Core 2.x into WPF application. Unfortunatelly, ASP.NET Core 3.0 and later will only run on .NET Core.
I have some bits here and there but not a working concept. My options could be:
How to implement the web server/service(s) at WPF side? Maybe there is an existing 3rd party framework which could save me from reinventing the wheel?
PS. There is a similar question how to expose a restful service inside a WPF project but it is outdated.
Upvotes: 1
Views: 7099
Reputation: 143284
This sounds like your requirement:
WPF application should be able to expose an web API. This would be consumed by an web app.
But then you're against the only solution that would make it possible:
Launch a web server with web services from the WPF application. Sounds bad.
I'm not sure how else you're expecting being able to expose a Web API without launching a web server? Inside a UI App you'd want to launch a self-hosted Service.
In ServiceStack you can just start a self-hosted Service in your WPF App which can either be a self-hosted .NET Framework HTTP Listener or an ASP.NET Core on .NET Framework App. Both options Microsoft have said are going to be supported indefinitely, but .NET Framework is being phased out with ASP.NET Core 3.0 only going to run on .NET Core and .NET Framework stopping development at v4.x as .NET 5 is just going to be the next version of .NET Core.
But that shouldn't change what solutions are available to you now, if you need to run a Web Service in a WPF .NET Framework App you'll need to run a self-hosted .NET Framework HTTP Server which can either be a self-hosted HTTP Listener or ASP.NET Core (on .NET FX) App.
Upvotes: 3