Клиент gRPC-> Ошибка подключения к серверу - сервер возвратил неверный или нераспознанный ответ - PullRequest
0 голосов
/ 17 июня 2019

Я собрал пару gRPC (клиент + сервис Greeter) как MS, описанную здесь

и попытался запустить. Я получил

Журнал Сервера:

dbug: Grpc.AspNetCore.Server.Internal.GrpcServiceBinder[1]
Added gRPC method 'SayHello' to service 'Greet.Greeter'. Method type: 'Unary', route pattern: '/Greet.Greeter/SayHello'.
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:50051
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: E:\gRPC\GrpcGreeter\GrpcGreeter
info: Microsoft.AspNetCore.Server.Kestrel[29]
Connection id "0HLNJ0DILMG0A": HTTP/2 connection error.
Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2ConnectionErrorException: HTTP/2 connection error (PROTOCOL_ERROR): Invalid HTTP/2 connection preface.
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.ParsePreface(ReadOnlySequence1& buffer, SequencePosition& consumed, SequencePosition& examined) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.TryReadPrefaceAsync() at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2.Http2Connection.ProcessRequestsAsync[TContext](IHttpApplication1 application)

лог клиента

Unhandled Exception: System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.IO.IOException: The server returned an invalid or unrecognized response.
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.HttpClient.FinishSendAsyncUnbuffered(Task1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) at Grpc.Net.Client.Internal.GrpcCall2.SendAsync(HttpClient client, HttpRequestMessage message)
at Grpc.Net.Client.Internal.GrpcCall`2.GetResponseHeadersAsync()
E:\gRPC\GrpcGreeterClient\GrpcGreeterClient\bin\Debug\netcoreapp3.0\GrpcGreeterClient.exe (process 17980) exited with code -532462766.
Press any key to close this window . . .

Я добавил правило брандмауэра для 50051, но опять те же ошибки. Как исправить ошибку? Что я делаю не так?

1 Ответ

0 голосов
/ 17 июня 2019
  1. Сайт документа ASPNET.Core содержит ошибки: Мое клиентское приложение + приложение сервера gRPC от github работает. Причины заключаются в жестко закодированных URL-адресах и в клиентском Program.cs:

    var channel = new Channel ("localhost: 50051", ChannelCredentials.Insecure);

против

var httpClient = new HttpClient();
// The port number(50051) must match the port of the gRPC server.
 httpClient.BaseAddress = new Uri("http://localhost:50051");
  1. Кроме того, посмотрите на файл launchSettings.json и убедитесь, что он содержит правильные данные.
...