I created a basic gRPC Server using VS 2022 and want to run it as a Windows Service. The program runs fine in VS or Command line but when it's run as a service, it doesn't listen to the specified ports (6276). netstat doesn't show the port when it's a service but does otherwise. I'm running the service under an administrator account.
var options = new WebApplicationOptions
{
Args = args,
ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default
};
var builder = WebApplication.CreateBuilder(options);
builder.Services.AddGrpc();
builder.Host
.UseWindowsService(options =>
{
options.ServiceName = "CADE eTutor Service Core";
});
builder.WebHost.UseKestrel(kestrel =>
{
kestrel.ConfigureHttpsDefaults(https =>
{
https.ServerCertificate = new X509Certificate2(@"D:\Data\CADE.core\LDNcert.pfx", "pw");
});
});
var app = builder.Build();
// Configure the HTTP request pipeline.
app.MapGrpcService<eTutorServiceMain>();
app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
app.Run();
launchsettings.json
{
"profiles": {
"eTutorService": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://srdev.learn.net:6276",
"dotnetRunMessages": true
}
}
}
What am I missing?