robin sluyter
robin sluyter

Reputation: 41

.net Core Grpc Client unable to call Greeter Service

I have been looking at this for a long time, looking through all the different posts on the internet to see if I could find someone with the same issue but somehow I seem to be the only have having this issue.

I have an ASP.net Core server running the basic greeter service of Grpc. Calling this server using the program "BloomRPG" work great, and has excellent response times. However when I try to do the same from my own written (very basic) client I get the following errors:

On the Client:

dbug: Grpc.Net.Client.Internal.GrpcCall[1] Starting gRPC call. Method type: 'Unary', URI: 'https://www.MYSERVER.com:50005/greet.Greeter/SayHello'. dbug: Grpc.Net.Client.Internal.GrpcCall[18] Sending message. trce: Grpc.Net.Client.Internal.GrpcCall[21] Serialized 'TestService1.HelloRequest' to 15 byte message. trce: Grpc.Net.Client.Internal.GrpcCall[19] Message sent. fail: Grpc.Net.Client.Internal.GrpcCall[6] Error starting gRPC call. System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.IO.IOException: The response ended prematurely. at System.Net.Http.HttpConnection.FillAsync() at System.Net.Http.HttpConnection.ReadNextResponseHeaderLineAsync(Boolean foldedHeadersAllowed) at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) at Grpc.Net.Client.Internal.GrpcCall2.RunCall(HttpRequestMessage request, Nullable1 timeout) info: Grpc.Net.Client.Internal.GrpcCall[3] Call failed with gRPC error status. Status code: 'Internal', Message: 'Error starting gRPC call. HttpRequestException: An error occurred while sending the request. IOException: The response ended prematurely.'. dbug: Grpc.Net.Client.Internal.GrpcCall[4] Finished gRPC call. dbug: Grpc.Net.Client.Internal.GrpcCall[8] gRPC call canceled. Unhandled exception. Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: An error occurred while sending the request. IOException: The response ended prematurely.", DebugException="System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.IO.IOException: The response ended prematurely. at System.Net.Http.HttpConnection.FillAsync() at System.Net.Http.HttpConnection.ReadNextResponseHeaderLineAsync(Boolean foldedHeadersAllowed) at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) at Grpc.Net.Client.Internal.GrpcCall2.RunCall(HttpRequestMessage request, Nullable1 timeout)") at GrpcGreeterClient.Program.Main(String[] args) in C:\Users\MYUSERNAME\source\repos\grpc\TestgrpcClient\TestgrpcClient\Program.cs:line 64 at GrpcGreeterClient.Program.(String[] args) s

on the server:

fail: Microsoft.AspNetCore.Server.Kestrel[0] HTTP/2 over TLS was not negotiated on an HTTP/2-only endpoint.

Since I am succesfully calling the service with BloomRPC I suppose the issue is with my client:

Client code:

        AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);


        var loggerFactory = LoggerFactory.Create(logging =>
        {
            logging.AddConsole();
            logging.SetMinimumLevel(LogLevel.Trace);
        });


        var httpclient = new HttpClient();
        httpclient.DefaultRequestVersion = new Version(2, 0);

        




        using var channel = GrpcChannel.ForAddress("https://www.MYSERVER.com:50005",
            new GrpcChannelOptions { LoggerFactory = loggerFactory, HttpClient = httpclient});
        

        var client = new Greeter.GreeterClient(channel);
        
        var reply = await client.SayHelloAsync(
                          new HelloRequest { Name = "GreeterClient" });
        Console.WriteLine("Greeting: " + reply.Message);
        Console.WriteLine("Press any key to exit...");
        Console.ReadKey();
        

anyone have any idea what I could try next? I feel like I have exhausted all my options :(

Upvotes: 2

Views: 7317

Answers (1)

robin sluyter
robin sluyter

Reputation: 41

Thanks to @jdweng I figured out what was causing the issue.

a mandatory company proxy server was interfering, setting the UseProxy = false in the httpclienthandler fixed the issue for me and I am now able to call my gRPC server without problems!

Upvotes: 2

Related Questions