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")'