【发布时间】:2019-06-17 09:30:59
【问题描述】:
我已将 gRPC 对(客户端+Greeter 服务)构建为 MS described here
并试图运行。我收到了
服务器日志:
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 添加了防火墙规则,但同样的错误再次出现。 如何修复错误? 我做错了什么?
【问题讨论】:
-
它在 localhost:50051 上监听?它肯定需要侦听所有 IP 或至少要联系的网络的主 IP - 但看起来你要联系 - 你需要检查响应是什么......除了“错误”
-
我找到了错误的原因:MS doc 包含错误,以及他们的 github 代码示例。再次:需要小心;-)
标签: c# asp.net-core grpc