简体   繁体   English

Web API 作为 windows 服务

[英]Web API as a windows service

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? 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.我可以在 VS 中本地运行 API,它会打开 Chrome 并在它启动的本地 IIS 服务器下显示响应。 How do I take this same project and compile it as a windows service while still using HTTPS?如何在仍然使用 HTTPS 的同时将同一个项目编译为 windows 服务?

Web API is fully capable of being self hosted on top of OWIN , and does not require IIS to run. Web API 完全能够自托管在 OWIN 之上,并且不需要 IIS 即可运行。

Web API self hosted is basically just a console app. Web API 自托管基本上只是一个控制台应用程序。 So the techniques for turning a Web API console app into a Windows Service are the same as for any other .NET console app.因此,将 Web API 控制台应用程序转换为 Windows 服务的技术与任何其他 Z303CB0EF5825D9072AZ6 控制台应用程序相同。 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 .您可以使用诸如NSSM之类的服务管理器,或直接创建一个 Windows 服务项目(通过从适当的类继承,相当混乱)或使用诸如TopShelf之类的库。

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. IIS 提供了许多开箱即用的安全优势,旨在防止恶意请求。 If you're planning to publicly expose it, make sure you stick a proxy in front of it that will fulfill those security needs.如果您打算公开公开它,请确保在其前面放置一个能够满足这些安全需求的代理。

As far as i know you can only do that using .NET Core据我所知,您只能使用 .NET Core 来做到这一点

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-3.0&tabs=visual-studio https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-3.0&tabs=visual-studio

For.Net Framework you need to host your web application on IIS For.Net Framework,您需要在 IIS 上托管 web 应用程序

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM