I have followed the basic setup guide, but I seem to just end up getting 502 Bad Gateway responses when I test hitting a GRPC endpoint. Reaching the REST-stuff works. All examples I find seem to only contain gRPC endpoints, so they don't really care about making it work alongside other stuff.
Locally, I explicitly set ports to listen to like below, and this works fine (REST on 5025, HTTP1, gRPC on 5026, HTTP2).
if (app.Environment.IsDevelopment())
{
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(5025, opts => opts.Protocols = HttpProtocols.Http1 );
options.ListenAnyIP(5026, opts => opts.Protocols = HttpProtocols.Http2 );
});
}
However, when deploying to real environments, this should be controlled from the Azure App Service, as far as I know. I don't have that much experience with them and all their magic env vars and settings, but the app has previously run with only REST without any explicitly configured ports.
The app is built as a container, with the following setup (along with dotnet publish ... /t:PublishContainer
):
<PropertyGroup>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<EnableSdkContainerDebugging>True</EnableSdkContainerDebugging>
<ContainerBaseImage>mcr.microsoft.com/dotnet/aspnet:9.0</ContainerBaseImage>
<ContainerRepository>app-name</ContainerRepository>
</PropertyGroup>
<ItemGroup>
<ContainerEnvironmentVariable Include="ASPNETCORE_HTTPS_PORTS">
<Value>8081</Value>
</ContainerEnvironmentVariable>
</ItemGroup>
If I configure Kestrel to default to HTTP2, it seems like the REST-APIs stop working properly (although I guess that could depend on the client used for testing - I use Postman). Same if I do Http1AndHttp2
.
The gRPC-services are added in Program.cs
in the textbook way with app.MapGrpcService<MyGrpcService>()
.
Is it even possible for this to happen on a single port, or do I explicitly need to listen on two different ports - one for gRPC and one for REST?
We landed on explicitly configuring different ports, which made everything work - and then use the same values for every environment. Not too shabby. App service then manages this for you, so you don't need to add port number to the URL you call on the consuming side.
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(8080, opts => opts.Protocols = HttpProtocols.Http1 );
options.ListenAnyIP(8585, opts => opts.Protocols = HttpProtocols.Http2 );
});