grpc 错误记录一下 掉坑里爬了三天

Posted jasonabc

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了grpc 错误记录一下 掉坑里爬了三天相关的知识,希望对你有一定的参考价值。

RpcException: Status(StatusCode=Internal, Detail="Error starting gRPC call. HttpRequestException: An error occurred while sending the request. IOException: The response ended prematurely, with at least 9 additional bytes expected.")

  经常报这样的错我。我把坑了好几天。。。

记录一下

第一步   制定kestrel  监听的端口    并制定是http2 协议

  public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.ConfigureKestrel(option =>
                    {
                        option.ListenLocalhost(5001, o => o.Protocols = Microsoft.AspNetCore.Server.Kestrel.Core.HttpProtocols.Http2);
                    });
                    webBuilder.UseStartup<Startup>();
                });
    }

  第二部 客户端调用时候 

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

                string targetUrl = "http://localhost:5001";
                using (var channel = GrpcChannel.ForAddress(targetUrl))
                {
                    var client = new Score.ScoreClient(channel);

                    Console.WriteLine("***************单次调用************");
                    {
                        var reply = await client.GetScoreAsync(new ScoreRequest() { LessonId = "123" });
                        string result = Newtonsoft.Json.JsonConvert.SerializeObject(reply.Score);
                        Console.WriteLine($"ScoreClient {Thread.CurrentThread.ManagedThreadId} 服务返回数据1:{result} ");
                        base.ViewBag.Result = result;
                    }
                }

 

以上是关于grpc 错误记录一下 掉坑里爬了三天的主要内容,如果未能解决你的问题,请参考以下文章

入坑?那就从坑里爬出来

掉坑里出不来系列之JS的Event Loop

微信小程序到处都是坑怎么办?

springboot + rabbitmq 用了消息确认机制,感觉掉坑里了

终于掉坑里了!!!vue-resource和jquery的ajax不一样

漫画 | 写了三天的日报,我闪人了!