You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 6的gRPC客户端无法连接.NET 4.8的gRPC服务器

问题原因与修复方案
  • 问题根源:你的gRPC服务器仅绑定了localhost(127.0.0.1)地址,这会让服务只监听本机回环接口,无法接收来自局域网内虚拟机的连接请求——即便两者能互相ping通,外部IP的请求也会被拒绝。
  • 代码佐证:服务器代码中ServerPort的第一个参数是"localhost",这是限制连接范围的关键:
    // 原错误配置
    Ports = { new ServerPort("localhost", 7001, ServerCredentials.Insecure) }
    
  • 修复步骤:将绑定地址改为"0.0.0.0",让服务器监听所有可用的网络接口,包括实体机的局域网IP:
    server = new Server 
    {
        Ports = { new ServerPort("0.0.0.0", 7001, ServerCredentials.Insecure) }, 
        
        Services = 
        {
            ExtractorRpcService.BindService(this.extractorService),
            ThermocyclerRpcService.BindService(this.thermocyclerService)
        }
    };
    
  • 补充说明:客户端代码的配置是正确的——已经开启HTTP2明文支持并跳过了证书验证,修改服务器绑定地址后即可正常建立连接。

内容的提问来源于stack exchange,提问作者Sergey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 02:06:27