当前位置: 首页 > 知识库问答 >
问题:

从。NET Framework客户端调用gRPC服务器时出现异常

百里海超
2023-03-14

我有一个用。NET核心实现的gRPC服务器,我希望与运行在。NET Framework中的控制台应用程序联系。

class Program
{
    static async Task Main(string[] args)
    {
        
        var input = new MyModel();

        var channel = GrpcChannel.ForAddress("https://localhost:5001");
        var client = new Test.TestClient(channel);

        var reply = await client.SetTestAsync(input);

        Console.ReadLine();
    }
}
class Program
{
    static void Main(string[] args)
    {
        Channel channel = new Channel("https://localhost:5001", ChannelCredentials.Insecure);
        
        var    client = new Test.TestClient(channel);

        MyModel request = new MyModel();

        var reply = client.SetTest(request);

        channel.ShutdownAsync().Wait();


        Console.ReadLine();
    }
}

我在发送请求时得到以下异常:

rpc.core.rpcexception:'statuscode=“不可用”,detail=“DNS解析失败服务:https://localhost:5001”,debugexception=“grpc.core.internal.coreerrordetailexception=”created“:”@1600333768.0550000“,”description“:”解析器瞬态失败“,”file“:”8.0550000“,”说明“:”DNS解析服务失败:https://localhost:5001“,”文件“:”t:\src\github\grpc\workspace_csharp_ext_windows_x86\src\core\ext\filters\client_channel\resolver\DNS\c_ares\dns_resolver_ares.cc“,”文件_line“:378,”grpc_status“:14,”referenced_errors“:[{”created“:”@1600333768.0550000“,”说明“:”c-ares 0:无法联系DNS服务器“,”文件“:”t:\src\github\grpc\workspace_csharp_ext_windows_x86\src\core\ext\filters\client_channel\resolver\DNS\c_ares\grpc_ares_wrapper.cc“,”file_line“:287,”referenced_errors“:[{”created“:”@1600333768.0550000“,”description“:”C-ares状态不是ARES_SUCCESS qtype=aaaa name=https://localhost:5001 is_balancer=0:不能联系DNS服务器“,”file“:”]}“)‘

在服务器上,我得到以下错误:

DBUG:microsoft.aspnetcore.server.kestrel[17]连接id“0HM2QU64LCR9J”错误请求数据:“无法识别的HTTP版本:'HTTP/2.0'”Microsoft.aspnetcore.server.kestrel.core.badHttpRequestException:无法识别的HTTP版本:Microsoft.aspnetcore.server.kestrel.core.internal.HTTP.httpparser1。rejectunknownversion(Byte*版本,Int32长度)在microsoft.aspnetcore.server.kestrel.core.internal.HTTP.httpparser1.microsoft.aspnetcore.server.kestrel.core.internal.HTTP.httpparser1.microsoft.aspnetcore.server.kestrel.core.kestrel.core.internal.HTTP.iHttpParser1.parserequestline(TRequestHandler处理程序,readonlySequence,Int32 length)xamined)在Microsoft.aspnetcore.server.kestrel.core.internal.http.http1Connection.takeStartline(readonlySequence1&缓冲区,sequencePosition&已消费,sequencePosition&已检查)在Microsoft.aspnetcore.server.kestrel.core.internal.http1Connection.parserequest(readonlySequence1&缓冲区,sequencePosition&已消费,sequencePosition&已检查)在.http.httpprotocol.processRequests[TContext](ihttpapplication1应用程序)位于Microsoft.aspnetcore.server.kestrel.core.internal.httpprotocol.processRequestSasync[TContext](ihttpapplication1应用程序)dbug:microsoft.aspnetcore.server.kestrel.core.internal.httpprotocol.processRequestSasync[TContext](ihttpapplication1应用程序)连接id“0HM2QU64LCR9J”KETS[6]连接id“0HM2QU64LCR9J”接收到FIN。DBUG:microsoft.aspnetcore.server.kestrel.transport.sockets[7]连接id“0HM2QU64LCR9J”发送FIN,因为:“套接字传输的发送循环顺利完成。”

按照建议在Kestrel中添加了HTTP/2支持,但仍然得到了一个错误:

rpc.core.rpcexception:'status(statuscode=“unknown”,detail=“received http2 header with status:307”,debugexception=“grpc.core.internal.coreerrordetailexception=”grpc.core.internal.coreerrordetailexception:{“created”:“@1600342649.633000000”,“description”:“received http2:status header with non-200 OK status”,“file”“status”:2,“value”:“307”}“)‘


共有1个答案

岳彬炳
2023-03-14

我不相信channel的构造函数参数希望值为URI格式;您最好的选择可能是:

Channel channel = new Channel("localhost", 5001, ChannelCredentials.Insecure)

尽管它也可能作为:

Channel channel = new Channel("localhost:5001", ChannelCredentials.Insecure);
 类似资料:
  • 快速免责声明,我是非常新的gRPC和RPC一般,所以请有耐心 对等点列表、是在以前的rpc调用中构建的。 客户 服务器端实现,

  • 有可能从客户端向服务器抛出异常吗?我们有一个从服务器到客户端的开放流: 当我尝试这样的事情时: 我在客户端的StreamObserver.on错误中获得了异常,但在服务器端没有异常。

  • 我正在尝试使用hazelcast v3。2.4(服务器和客户端上的版本相同)。服务器(我可以安装的简单实现)正在服务器上运行。客户端尝试连接到远程服务器-服务器打印身份验证请求,但我收到以下日志输出(包括异常)-关于我可以做什么不同的想法(复制日志输出和配置文件)。我正在尝试通过TCP/IP进行连接,我检查了网络连接——我没有看到任何东西阻止连接。 堆栈中提到的代码行: 配置 日志输出 服务器输出

  • C Async描述了如何创建一个异步服务器和一个相应的异步客户机来与之通信。我已经在微软ViualStudio中创建了这个。 我现在需要一个java客户端说话的C服务器-我无法找到一个Java等效的客户端(到C)与C通信。 任何指点都将不胜感激

  • 我对gRpc很陌生,已经开始探索它们的基础知识(在C语言中)。我想获得有关如何发送心跳以检查客户端/服务器是否仍处于连接状态以及在断开连接时采取恢复措施的指导。任何示例或参考任何文档/文章都将有助于我开始学习。谢谢

  • 我已经看了很长一段时间了,在互联网上浏览了所有不同的帖子,看看是否能找到有相同问题的人,但不知为什么,我似乎是唯一有这个问题的人。 我有一个ASP。net核心服务器,运行Grpc的基本迎宾服务。使用程序“BloomRPG”调用此服务器效果很好,而且响应时间也很长。然而,当我试图从自己编写的(非常基本的)客户机上执行同样的操作时,我会遇到以下错误: 在客户机上: dbug:Grpc。网客户内部的Gr