gpt4 book ai didi

c# - 如何连接到远程 gRPC 服务

转载 作者:行者123 更新时间:2023-12-04 15:34:34 31 4
gpt4 key购买 nike

我在 C# .NET Core 3.1 中创建了一个 gRPC 服务和客户端。当我将服务部署到 localhost 时,我可以毫无问题地连接到它。但是当我通过 WebDeploy 将服务发布到 IIS 并在那里启动它时,我无法连接到它。

对于本地部署, channel 初始化如下:
var channel = GrpcChannel.ForAddress("https://localhost:5001");
对于远程部署,我将其更改为以下值,因为它在 http://localhost:5000 上作为 HTTP 服务启动在远程机器上(我也没有找到如何更改 - 我更喜欢它作为 HTTPS 服务启动):

AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
var channel = GrpcChannel.ForAddress("http://1.2.3.4:5000");
1.2.3.4是远程机器的IP,我可以ping通。我还创建了一个防火墙规则以允许入站端口 5000 上的所有入站流量.

客户端应用程序在第一次远程调用时失败并显示错误消息
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
我不明白我必须采取哪些措施来创建到远程服务的连接。到目前为止我发现的所有示例 gRPC 代码都使用 localhost作为部署点,并没有帮助我找出问题的根本原因。

感谢您对我必须错过的任何帮助或指示。

最佳答案

来自 Tutorial: Create a gRPC client and server in ASP.NET Core ,几乎在文章末尾的警告说

ASP.NET Core gRPC is not currently supported on Azure App Service or IIS. The HTTP/2 implementation of Http.Sys does not support HTTP response trailing headers which gRPC relies on...



请引用 gRPC in production了解在生产中运行 gRPC 服务的方法。

关于c# - 如何连接到远程 gRPC 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60171649/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com