https://github.com/jordicorbilla/windowsservicehost
Hosting a .NET 5 webAPI in a Windows Service
https://github.com/jordicorbilla/windowsservicehost
csharp https net5 webapi windowsservices
Last synced: 9 months ago
JSON representation
Hosting a .NET 5 webAPI in a Windows Service
- Host: GitHub
- URL: https://github.com/jordicorbilla/windowsservicehost
- Owner: JordiCorbilla
- License: mit
- Created: 2020-11-16T18:21:30.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2020-12-12T08:36:31.000Z (about 5 years ago)
- Last Synced: 2025-02-16T08:26:33.413Z (11 months ago)
- Topics: csharp, https, net5, webapi, windowsservices
- Language: C#
- Homepage:
- Size: 61.5 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Windows Service Host
**Hosting a .NET 5 WebAPI in a Windows Service**
This project serves as a template to scaffold your Swagger Web API projects using .net 5 and hosting it in a Windows Service. As it's built using only .net 5, you can launch the project locally on IIS Express, as a command line tool or as a windows service. Using the windows service approach will let you host it on your server without having to use IIS.
### Create the service
```powershell
C:\>sc create HostedService binpath=C:\WindowsServiceHostTemplate\bin\Debug\net5.0\WindowsServiceHostTemplate.exe
[SC] CreateService SUCCESS
C:\WINDOWS\system32>sc start HostedService
```
### Starting the solution as a console app
You can run the application as a simple console app and see the same results:
```powershell
C:\WindowsServiceHostTemplate\bin\Debug\net5.0>WindowsServiceHostTemplate.exe
info: WindowsServiceHostTemplate.Worker[0]
Worker running at: 11/18/2020 20:18:42 +00:00
[20:18:42 INF] Starting...
info: WindowsServiceHostTemplate.Worker[0]
Worker running at: 11/18/2020 20:18:43 +00:00
[20:18:43 INF] Worker running at: 11/18/2020 20:18:43 +00:00
info: WindowsServiceHostTemplate.Worker[0]
Worker running at: 11/18/2020 20:18:44 +00:00
[20:18:44 INF] Worker running at: 11/18/2020 20:18:44 +00:00
[info20:18:44: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
INF] Now listening on: http://localhost:5000
[info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://localhost:5001
20:18:44 INF] Now listening on: https://localhost:5001
[info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
20:18:44 INF] Application started. Press Ctrl+C to shut down.
[info20:18:44: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
INF] Hosting environment: Production
[info20:18:44: Microsoft.Hosting.Lifetime[0]
Content root path: C:\WindowsServiceHostTemplate\bin\Debug\net5.0
INF] Content root path: C:\WindowsServiceHostTemplate\bin\Debug\net5.0
info[: WindowsServiceHostTemplate.Worker[0]
Worker running at: 11/18/2020 20:18:45 +00:00
20:18:45 INF] Worker running at: 11/18/2020 20:18:45 +00:00
[info20:18:46: WindowsServiceHostTemplate.Worker[0]
Worker running at: 11/18/2020 20:18:46 +00:00
INF] Worker running at: 11/18/2020 20:18:46 +00:00
info[: WindowsServiceHostTemplate.Worker[0]
Worker running at: 11/18/2020 20:18:47 +00:00
```
### Navigate to the API
Once the application is running, navigate here -> and you'll see the data.
And also here for the Swagger API ->

### Packages Used
```xml
```