[英]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.