如何从 WPF 应用程序提供 RESTful 个 Web 服务?
How to provide RESTful web service(s) from WPF application?
WPF 应用程序通常是 Web 服务器上 RESTful 服务的 consumer/client。我想将其反转 - WPF 应用程序应该能够公开 Web API。这将由网络应用程序使用。
流量:
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
通信应采用Json格式。我准备好了OpenAPI (in YAML) schema for it at the http://editor.swagger.io/。将来它可用于更改 WPF 应用程序的 Web API.
它允许生成 ASP.NET 核心服务器 c# 代码存根。 运行 ASP.NET WPF 中的核心服务器有什么要求,它是否足够轻便?
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
// somewhere in the WPF app: BuildWebHost(args).Run();
代码由https://github.com/swagger-api/swagger-codegen自动生成。
有一个 无法将 ASP.NET Core 2.x 集成到 WPF 应用程序中。不幸的是,ASP.NET Core 3.0 及更高版本将仅在 .NET Core 上 运行。
我在这里和那里有一些想法,但不是一个可行的概念。我的选择可能是:
- 使用第 3 方框架或库。应该能够使用 OpenAPI/YAML 架构或 Swagger 生成的服务器存根代码等。
- ServiceStack 会是这里缺失的部分吗?
- 将 ASP.NET 核心集成到 WPF 中。有可能吗?
- 使用来自 WPF 应用程序的 Web 服务启动一个单独的 Web 服务器(不是自托管)。听起来很糟糕。
- 实施 WCF Web 服务和请求。
- ...
如何在WPF端实现web server/service(s)?也许有一个现有的第 3 方框架可以让我免于重新发明轮子?
PS。有一个类似的问题 但它已经过时了。
这听起来像您的要求:
WPF application should be able to expose an web API. This would be consumed by an web app.
但是你反对的唯一解决方案是:
Launch a web server with web services from the WPF application. Sounds bad.
我不确定您还期望如何在不启动 Web 服务器的情况下公开 Web API?在 UI 应用程序中,您想要启动 self-hosted 服务。
自托管
在 ServiceStack 中你可以只启动一个 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.
但这不应改变您现在可以使用的解决方案,如果您需要 运行 WPF .NET Framework 应用程序中的 Web 服务,您将需要 运行 self-hosted .NET Framework HTTP 服务器,可以是 self-hosted HTTP 侦听器或 ASP.NET 核心(在 .NET FX 上)应用程序。
WPF 应用程序通常是 Web 服务器上 RESTful 服务的 consumer/client。我想将其反转 - WPF 应用程序应该能够公开 Web API。这将由网络应用程序使用。
流量:
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
通信应采用Json格式。我准备好了OpenAPI (in YAML) schema for it at the http://editor.swagger.io/。将来它可用于更改 WPF 应用程序的 Web API.
它允许生成 ASP.NET 核心服务器 c# 代码存根。 运行 ASP.NET WPF 中的核心服务器有什么要求,它是否足够轻便?
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
// somewhere in the WPF app: BuildWebHost(args).Run();
代码由https://github.com/swagger-api/swagger-codegen自动生成。
有一个
我在这里和那里有一些想法,但不是一个可行的概念。我的选择可能是:
- 使用第 3 方框架或库。应该能够使用 OpenAPI/YAML 架构或 Swagger 生成的服务器存根代码等。
- ServiceStack 会是这里缺失的部分吗?
- 将 ASP.NET 核心集成到 WPF 中。有可能吗?
- 使用来自 WPF 应用程序的 Web 服务启动一个单独的 Web 服务器(不是自托管)。听起来很糟糕。
- 实施 WCF Web 服务和请求。
- ...
如何在WPF端实现web server/service(s)?也许有一个现有的第 3 方框架可以让我免于重新发明轮子?
PS。有一个类似的问题
这听起来像您的要求:
WPF application should be able to expose an web API. This would be consumed by an web app.
但是你反对的唯一解决方案是:
Launch a web server with web services from the WPF application. Sounds bad.
我不确定您还期望如何在不启动 Web 服务器的情况下公开 Web API?在 UI 应用程序中,您想要启动 self-hosted 服务。
自托管
在 ServiceStack 中你可以只启动一个 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.
但这不应改变您现在可以使用的解决方案,如果您需要 运行 WPF .NET Framework 应用程序中的 Web 服务,您将需要 运行 self-hosted .NET Framework HTTP 服务器,可以是 self-hosted HTTP 侦听器或 ASP.NET 核心(在 .NET FX 上)应用程序。