In this post I’ll show you how to publish a ASPNET.Core gRPC server to a Windows 2019 Server as a windows service.
gRPC is a high performance remote procedure call framework. With gRPC you can create real time services which can stream requests and responses. Since the release of .NET Core version 3.0 you can find a gRPC Service project template in Visual Studio 2019.
During development you can easily test and debug your gRPC server on your development machine without any configurations. You can also publish your gRPC service as a windows service by performing following steps.
To enable running your server project as windows service you need to first add “Microsoft.Extensions.Hosting.WindowsServices” NuGet package to your project.
Moreover, add “UseWindowsService()” statement to the Host.CreateDefaultBuilder configuration in Program.cs:
Then create a publish profile for the project by selecting “Publish” from project context menu. You can select “FolderProfile” as a publish type and get all the necessary files in a publish folder.
Once all the files are copied to the destination Windows 2019 server, you can register your service with the following command on Windows PowerShell.
sc.exe create WindowsServiceName binpath= C:\gRPCSampleServer\Server.exe start= auto
Since the project is .Net Core based you need to install the .Net Core hosting bundle to the server (at the time of this writing the latest version is dotnet-hosting-3.1.2-win). You can download the hosting bundle from https://dotnet.microsoft.com/download/dotnet-core.
.NET Core gRPC requires SSL connection by default. Therefore, you need to have a SSL certificate for…