最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net core - gRPC and REST side by side in Azure App Service, Linux Container - Stack Overflow

programmeradmin0浏览0评论

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/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?

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?

Share Improve this question asked Feb 6 at 15:52 Arve SystadArve Systad 5,4791 gold badge34 silver badges59 bronze badges 4
  • Try set Port Value in Environment Variable section of Azure Web App Name = HTTP20_ONLY_PORT Value = 8585, like this. – Aslesha Kantamsetti Commented Feb 6 at 16:31
  • It's in place, as it is also described in the basic setup docs I linked to. Still no valid responses for gRPC. – Arve Systad Commented Feb 6 at 17:24
  • Have you enabled HTTP/2 support in the portal? davecallan.com/how-to-enable-http-2-on-azure-app-service-apps – Tore Nestenius Commented 10 hours ago
  • Yes. This is described in the setup docs I linked to :-) – Arve Systad Commented 8 hours ago
Add a comment  | 

1 Answer 1

Reset to default 0

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 );
});
发布评论

评论列表(0)

  1. 暂无评论