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;
                    }
                }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM