Is it possible to use gRPC with HTTP/1.1 in .NET Core?
Asked Answered
C

4

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?

Crannog answered 16/1, 2020 at 13:31 Comment(0)
R
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)

Romanism answered 16/1, 2020 at 13:36 Comment(7)
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? ThanksAustin
@Austin what makes you think that? Pretty sure it is http/2, because gRPC is defined as http/2Romanism
@Austin also, new Channel is the Google transport, not the MS one, so it is chttp running http/2Romanism
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. ThanksAustin
@marco fyi, if you're after the MS transport: GrpcChannel.ForAddress(...)Romanism
What is the name of the nuget to install to get this 'Google transport implementation'?Carew
@Carew Grpc.CoreRomanism
P
3

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

Poverty answered 16/1, 2020 at 13:37 Comment(3)
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.Bonacci
@JamesRoper - implementing gRPC over http1.1 will not work for full duplex bidirectional rpc use-cases, where both parties need to communicate with each other simultaneously/independently at their own pace through the same channel.Hipped
Actually it will. There is nothing in http1.1 that prohibits full duplex communication over HTTP. The server is allowed to start sending its response body before the client has finished sending its request body. This is made clear in section 8.2.3 of RFC2616, where it describes exactly how the server should behave in this instance. Since both the client and server are allowed to send their message bodies at the same time, you can do full duplex streaming with this. akka-http supports full duplex streaming over HTTP/1.1 for this reason, for example.Bonacci
M
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.

Moxley answered 9/12, 2021 at 19:19 Comment(0)
M
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.

Magneto answered 20/1, 2022 at 23:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.