Reputation: 11
I am trying to set up a grpc-net client on a .net standard 2.0 project that is connected via an insecure channel to a grpc server running google's implementation.
The server side is running on a .NET 6.0 console app with google's grpc implementation:
var server = new Grpc.Core.Server()
{
Ports = { new ServerPort("localhost", 0, ServerCredentials.Insecure) },
Services = { Greeter.BindService(new GreeterServer()) }
};
server.Start();
The client side is running as a .net 4.7.2 console app (with the server port as input):
var channel = GrpcChannel.ForAddress("http://localhost:" + port, new GrpcChannelOptions
{
HttpHandler = new GrpcWebHandler(new HttpClientHandler()),
Credentials = ChannelCredentials.Insecure
});
var client = new Greeter.GreeterClient(channel);
The following exception is thrown on the client Channel creation:
Grpc.Core.RpcException: 'Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: An error occurred while sending the request. WebException: The server committed a protocol violation. Section=ResponseStatusLine", DebugException="System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The server committed a protocol violation. Section=ResponseStatusLine
at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context) at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar) --- End of inner exception stack trace --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Grpc.Net.Client.Web.GrpcWebHandler.d__18.MoveNext() in //src/Grpc.Net.Client.Web/GrpcWebHandler.cs:line 166 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Grpc.Net.Client.Internal.GrpcCall`2.d__73.MoveNext() in //src/Grpc.Net.Client/Internal/GrpcCall.cs:line 493")'
Upvotes: 1
Views: 1225
Reputation: 193
This error happened exactly by the reason described here (use http 1.1 while the server is using http2) as for your question in comments - Yes - it means that grpc-net client will not be able to connect to google's grpc server in the way you use it. I faced with a little bit more complex case when I was needed to connect to grpc server that work through HTTP 0.9, and it was the same exception. I found the way to do it. There is an implementation that use native gRPC Core library and the C# implementation. Here you will get ability to create channel. For your case, it will look like:
var channel = new Grpc.Core.Channel("localhost", port, ChannelCredentials.Insecure);
var client = new Greeter.GreeterClient(channel);
Be mind because it is on maintenance mode. Here you can read about it.
Upvotes: 2