Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

which is the difference between Grpc.Core.Channel and Grpc.Net.Client.GrpcChannel?

I am doing some tests with Grpc and I realize that there is this two types of channels, but I don't know the difference.

But when I am working with certificates, with Grpc.Net.Client.GrpcChannel I can set the certificates but I get an error that the DNS is not solved. If I use Grpc.Core.Channel, I can call to the service, but I get an error because of the certificates, with the error - HTTP/2 over TLS was not negotiated on an HTTP/2-only endpoint.

Which is the difference between the 2 channels?

Thanks.

like image 649
Álvaro García Avatar asked Dec 21 '19 19:12

Álvaro García


People also ask

What is a gRPC channel?

A gRPC channel provides a connection to a gRPC server on a specified host and port. It is used when creating a client stub. Clients can specify channel arguments to modify gRPC's default behavior, such as switching message compression on or off. A channel has state, including connected and idle .

What is gRPC .NET core?

gRPC is a language agnostic, high-performance Remote Procedure Call (RPC) framework. The main benefits of gRPC are: Modern, high-performance, lightweight RPC framework. Contract-first API development, using Protocol Buffers by default, allowing for language agnostic implementations.

Does gRPC work with .NET framework?

Limited support is available for gRPC over HTTP/2 on . NET Framework. Other . NET versions such as UWP, Xamarin and Unity don't have required HTTP/2 support, and must use gRPC-Web instead.

What is gRPC service in C#?

gRPC uses a contract-first approach to API development. Protocol buffers (protobuf) are used as the Interface Definition Language (IDL) by default. The . proto file contains: The definition of the gRPC service.


1 Answers

Grpc.Core.Channel is based on C Core libraries that forms the base codebase for all the language variants it supports (C++,C#, PHP, Objective-C, Python, Ruby etc)

Grpc.Net.Client.GrpcChannel is built for.NET Core using the familiar HttpClient object which supports Http/2 now.

The Homepage of grpc-dotnet states that:

GRPC for .NET does not replace gRPC for C# (gRPC C# API over native C-core binaries). These implementations coexist and share many of the same APIs to avoid lock-in. There are currently no plans for one implementation to replace the other one. gRPC for C# is the recommended solution for frameworks that gRPC for .NET does not support, such as .NET Framework.

When you inspect the code for Grpc.Net.Client.GrpcChannel, you can see an internal Httpclient object being used to make async calls and cancel pending requests.

The code for Grpc.Core.Channel seems to delegate its calls to the natively generated grpc code. This is about as far as I got in the limited time I could spend on it.

Interestingly, in the ssl validation part of the Net.Client.GrpcChannel, it actually states that it uses HttpClient in the exception messaging.

if (!string.IsNullOrEmpty(rootCertificates) ||
    keyCertificatePair != null ||
    verifyPeerCallback != null)
{
    throw new InvalidOperationException(
        $"{nameof(SslCredentials)} with non-null arguments is not supported by {nameof(GrpcChannel)}. " +
        $"{nameof(GrpcChannel)} uses HttpClient to make gRPC calls and HttpClient automatically loads root certificates from the operating system certificate store. " +
        $"Client certificates should be configured on HttpClient. See https://aka.ms/AA6we64 for details.");
}
like image 150
Francis Avatar answered Nov 14 '22 21:11

Francis