Skip to content

Grpc application hosted in azure container #2795

Closed

Description

@mukthiarahamad

Hi ,

I have created a sample Grpc application and have added the docker image to the Azure container registry. Have hosted the same in Azure container and when I am trying to consume the the container url in the client. I get an exception

Status(StatusCode="Internal", Detail="Bad gRPC response. Response protocol downgraded to HTTP/1.1.")'

Program.cs

.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup();
webBuilder.ConfigureKestrel(kestrel =>
{
kestrel.ConfigureEndpointDefaults(lo => lo.Protocols = HttpProtocols.Http2);

                    kestrel.ConfigureHttpsDefaults(https =>
                    {
                        https.ServerCertificate = new X509Certificate2("a.pfx", "Password");
                        https.SslProtocols = SslProtocols.Tls12;
                    });
                });
            });

app settings.json:

{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"Kestrel": {
"EndpointDefaults": {
"Protocols": "Http2"
}
}
}

Docker File:

FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["project/project.csproj", "project/"]
RUN dotnet restore "project/project.csproj"
COPY . .
WORKDIR "/src/project"
RUN dotnet build "project.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "project.csproj" -c Release -o /app/publish

FROM base AS final
ENV ASPNETCORE_URLS="https://+;http://+"
ENV ASPNETCORE_HTTPS_PORT=443
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "project.dll"]

Am I missing anything?

Activity

  1. mukthiarahamad commented on May 11, 2021

    @mukthiarahamad
    Author

    I am now trying to use the http protocol and have enable http2 on the port 5000. But I get the below issue while I connect to the client from grpc.

    Grpc.Core.RpcException: 'Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: Requesting HTTP version 2.0 with version policy RequestVersionOrHigher while HTTP/2 is not enabled.", DebugException="System.Net.Http.HttpRequestException: Requesting HTTP version 2.0 with version policy RequestVersionOrHigher while HTTP/2 is not enabled.
    at System.Net.Http.HttpConnectionPool.SendWithRetryAsync

    I have enable http2 in the server for port 5000

    webBuilder.ConfigureKestrel(options =>
    {
    // Setup a HTTP/2 endpoint without TLS.
    // options.ListenLocalhost(80, o => o.Protocols =
    // HttpProtocols.Http2);
    options.ListenAnyIP(5000, o => o.Protocols =
    HttpProtocols.Http2);
    });
    webBuilder.UseStartup();

    Kindly suggest.

  2. locked and limited conversation to collaborators on May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions