14

I have two network services - a gRPC client and gRPC server. Server is written in .NET Core, hence HTTP/2 for gRPC is enforced. Client however is a .NET Framework 4.7.2 web app hosted on IIS 8.5, so it only supports HTTP/1.1.

Since it will take some time to upgrade the client I was thinking if it is possible to use HTTP/1.1 instead of HTTP/2 on the server side, but I cannot find any information how to achieve that.

Is it possible to use HTTP/1.1 for gRPC server written in .NET Core? And if so - how?

GrayCat
  • 1,749
  • 3
  • 19
  • 30

4 Answers4

13

No, you cannot use gRPC on HTTP 1.1; you may be able to use the Grpc.Core Google transport implementation, however, instead of the managed Microsoft bits; this targets .NET Standard 1.5 and .NET Standard 2.0, so should work on .NET Core, and uses an OS-specific unmanaged binary (chttp2) for the transport.

For client-side, there is virtually no difference between the two; only the actual channel creation changes, between:

GrpcChannel.ForAddress(...)

with the Microsoft transport, and

new Channel(...)

with the Google transport. All of the rest of the APIs are shared (in Grpc.Core.Api)

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • If I use the Microsoft transport new Channel(...), then it must be HTTP/1.1 and not HTTP/2? How I can find the version of HTTP on a connected gRPC channel? Thanks – Marco Oct 04 '20 at 17:34
  • @Marco what makes you think that? Pretty sure it is http/2, because gRPC is *defined* as http/2 – Marc Gravell Oct 04 '20 at 20:02
  • @Marco also, `new Channel` is the Google transport, not the MS one, so it is chttp running http/2 – Marc Gravell Oct 04 '20 at 20:03
  • I looked at GRPC logs and there was no mention of HTTP/2, only "http". But the connection indeed kept alive as expected from HTTP/2. Thanks – Marco Oct 04 '20 at 20:10
  • 1
    @marco fyi, if you're after the MS transport: `GrpcChannel.ForAddress(...)` – Marc Gravell Oct 04 '20 at 20:12
3

No. The RPC call is done only over HTTP/2. This allows gRPC users to automatically leverage all the features of the protocol.

WhoKnows
  • 340
  • 1
  • 12
  • 2
    gRPC doesn't use any HTTP2 specific features that HTTP/1.1 doesn't have - response trailers are supported in HTTP/1.1 via chunked encoding, and client streaming is supported in HTTP/1.1 also via chunked encoding (a very rarely used HTTP/1.1 feature, but it's there). It's a myth that gRPC doesn't work on HTTP/1.1. – James Roper Jul 15 '21 at 03:31
1

If you don't need client streaming, you can Use the gRPC-Web protocol. Here's how you would start a client and server for such a service.

https://learn.microsoft.com/en-us/aspnet/core/grpc/browser?view=aspnetcore-6.0

Keep in mind that while it mentions blazor, this approach can be used in non-webassembly clients.

MHDante
  • 669
  • 1
  • 6
  • 16
0

Have you tried using grpc-web? I believe it has a workaround to use http1.1 instead of 2.2.

there are some things to be aware of, like trailers and streaming which work a bit different because of http1.1 support for those features.