简体   繁体   English

Windows Service .NET Core REST API

[英]Windows Service .NET Core REST API

I am trying to create a Windows Service using the .NET Core Web API template to respond to REST requests. 我正在尝试使用.NET Core Web API模板创建Windows服务来响应REST请求。

I have already managed to get a service up and running following these instructions ( https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-2.2&tabs=visual-studio ). 我已经设法按照以下说明启动并运行服务( https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-2.2&tabs=视觉工作室 )。 My issue is that I don't know how to have my Windows Service listen on a port for POST requests to its controllers. 我的问题是,我不知道如何让Windows服务在端口上侦听向其控制器发出的POST请求。

I've looked through some other StackOverflow solutions but from what I've seen they don't address this issue with the .NET Core Web API template. 我已经研究了其他一些StackOverflow解决方案,但是从我的观察来看,它们无法通过.NET Core Web API模板解决此问题。

I would like to send a request to some endpoint, say 'POST localhost:5000/api/endpoint' and have my Windows Service perform some task and return a status code (ie. 2xx, 4xx, 5xx). 我想向某个端点发送请求,例如“ POST localhost:5000 / api / endpoint”,并让我的Windows服务执行一些任务并返回状态代码(即2xx,4xx,5xx)。

There is UseUrls extension method which allows you to set up port. UseUrls扩展方法,可用于设置端口。

WebHost.CreateDefaultBuilder(args)
.UseUrls("http://*:5000")
.UseStartup<Startup>();

https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.hosting.hostingabstractionswebhostbuilderextensions.useurls?view=aspnetcore-2.2 https://docs.microsoft.com/zh-cn/dotnet/api/microsoft.aspnetcore.hosting.hostingabstractionswebhostbuilderextensions.useurls?view=aspnetcore-2.2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 .NET Core 3.1 API web 应用程序作为 Z0F4137ED1502B5045426083AA258 服务托管? - How to host a .NET Core 3.1 API web application as windows service? .net 核心 3.1 Web API 托管为 ZAEA23489CE3AA9B6406EBB28E0CDA 服务未显示页面 - .net core 3.1 Web API hosting as Windows Service not showing pages 在.net core中编写windows服务 - Writing windows service in .net core .NET Core Windows 服务与 Autofac - .NET Core Windows Service with Autofac .Net Core 2.0 Windows服务 - .Net Core 2.0 Windows Service For a REST stateless service layer in web API .net core 2+, which lifetime is preferred Transient or Singleton? - For a REST stateless service layer in web API .net core 2+, which lifetime is preferred Transient or Singleton? .NET Core 3.1 API Calling .NET Framework WCF Service secured using windows authentication (AD Group) - .NET Core 3.1 API Calling .NET Framework WCF Service secured using windows authentication (AD Group) 具有Windows Auth的.Net Core 2.0 REST API-使用401未经授权进行预检 - .Net Core 2.0 REST API w/ Windows Auth - Preflight responding with 401 Unauthorized 从Windows窗体调用.NET Core REST API以发送包括IFormFile的数据 - Calling .NET core REST api from windows forms to send data including IFormFile 如何使用 Angular 将 Windows 身份验证从客户端转发/传递到 ASP.NET Core 应用程序中的另一个 REST API? - How to forward/pass windows authentication from client to another REST API in an ASP.NET Core app with Angular?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM