Web API作为Windows服务 [英] Web API as a windows service

查看:426
本文介绍了Web API作为Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我要在Visual Studio 2019中创建一个新的.Net Framework 4.8 Web API,我想知道如何将API创建为Windows服务吗?我似乎找不到任何示例或在线资源.我可以在VS中本地运行该API,它会打开Chrome,并在它启动的本地IIS服务器下显示响应.在仍然使用HTTPS的情况下,如何处理这个项目并将其编译为Windows服务?

So I'm creating a new .Net Framework 4.8 Web API in Visual Studio 2019 and I'm wanting to know how to create the API as a windows service? I can't seem to find any examples or online resources to do so. I can run the API locally in VS and it opens Chrome and shows the responses under the local IIS Server it spins up. How do I take this same project and compile it as a windows service while still using HTTPS?

推荐答案

Web API是

Web API is fully capable of being self hosted on top of OWIN, and does not require IIS to run.

自托管的Web API基本上只是一个控制台应用程序.因此,将Web API控制台应用程序转换为Windows Service的技术与任何其他.NET控制台应用程序的技术相同.您可以使用服务管理器,例如 NSSM TopShelf 的库.

Web API self hosted is basically just a console app. So the techniques for turning a Web API console app into a Windows Service are the same as for any other .NET console app. You can use a service manager such as NSSM, or create a Windows service project directly (by inheriting from the appropriate classes, pretty messy) or use a library like TopShelf.

请注意,直接向公众公开此自托管应用通常不是一个好主意. IIS提供了许多开箱即用的安全保护功能,旨在防止恶意请求.如果您打算公开公开它,请确保在它前面放置一个可以满足这些安全需求的代理.

Note that it's generally not a good idea to directly expose this self hosted app directly to the public. IIS provides a lot of security benefits out of the box designed to protect against malicious requests. If you're planning to publicly expose it, make sure you stick a proxy in front of it that will fulfill those security needs.

这篇关于Web API作为Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆