5

I have a gRPC server implemented in .Net Core that I would like to contact with a console app running in .Net Framework.

Here is a working repo of the issue:

https://github.com/q-bertsuit/grpc-framework-core-issue

The following .Net Core Client works fine:

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

The following .Net Framework client throws an exception:

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

I get the following exception when sending the request:

Grpc.Core.RpcException: 'Status(StatusCode="Unavailable", Detail="DNS resolution failed for service: https://localhost:5001", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1600333768.055000000","description":"Resolver transient failure","file":"T:\src\github\grpc\workspace_csharp_ext_windows_x86\src\core\ext\filters\client_channel\resolving_lb_policy.cc","file_line":215,"referenced_errors":[{"created":"@1600333768.055000000","description":"DNS resolution failed for service: https://localhost:5001","file":"T:\src\github\grpc\workspace_csharp_ext_windows_x86\src\core\ext\filters\client_channel\resolver\dns\c_ares\dns_resolver_ares.cc","file_line":378,"grpc_status":14,"referenced_errors":[{"created":"@1600333768.055000000","description":"C-ares status is not ARES_SUCCESS qtype=A name=https://localhost:5001 is_balancer=0: Could not contact DNS servers","file":"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.055000000","description":"C-ares status is not ARES_SUCCESS qtype=AAAA name=https://localhost:5001 is_balancer=0: Could not contact DNS servers","file":"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}]}]}]}")'

On the server I get this error:

dbug: Microsoft.AspNetCore.Server.Kestrel[17] Connection id "0HM2QU64LCR9J" bad request data: "Unrecognized HTTP version: 'HTTP/2.0'" Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Unrecognized HTTP version: 'HTTP/2.0' at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpParser1.RejectUnknownVersion(Byte* version, Int32 length) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpParser1.ParseRequestLine(TRequestHandler handler, Byte* data, Int32 length) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpParser1.ParseRequestLine(TRequestHandler handler, ReadOnlySequence1& buffer, SequencePosition& consumed, SequencePosition& examined) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpParser1.Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.IHttpParser<TRequestHandler>.ParseRequestLine(TRequestHandler handler, ReadOnlySequence1& buffer, SequencePosition& consumed, SequencePosition& examined) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1Connection.TakeStartLine(ReadOnlySequence1& buffer, SequencePosition& consumed, SequencePosition& examined) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1Connection.ParseRequest(ReadOnlySequence1& buffer, SequencePosition& consumed, SequencePosition& examined) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1Connection.TryParseRequest(ReadResult result, Boolean& endConnection) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication1 application) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequestsAsync[TContext](IHttpApplication1 application) dbug: Microsoft.AspNetCore.Server.Kestrel[10] Connection id "0HM2QU64LCR9J" disconnecting. dbug: Microsoft.AspNetCore.Server.Kestrel[2] Connection id "0HM2QU64LCR9J" stopped. dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[6] Connection id "0HM2QU64LCR9J" received FIN. dbug: Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets[7] Connection id "0HM2QU64LCR9J" sending FIN because: "The Socket transport's send loop completed gracefully."

Added Http/2 support in Kestrel as suggested, but still got an error:

Grpc.Core.RpcException: 'Status(StatusCode="Unknown", Detail="Received http2 header with status: 307", DebugException="Grpc.Core.Internal.CoreErrorDetailException: {"created":"@1600342649.633000000","description":"Received http2 :status header with non-200 OK status","file":"T:\src\github\grpc\workspace_csharp_ext_windows_x86\src\core\ext\filters\http\client\http_client_filter.cc","file_line":130,"grpc_message":"Received http2 header with status: 307","grpc_status":2,"value":"307"}")'

Q-bertsuit
  • 3,223
  • 6
  • 30
  • 55

2 Answers2

2

I don't believe the constructor parameter for Channel expects the value to be in URI format; your best bet is probably:

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

although it may also work as:

Channel channel = new Channel("localhost:5001", ChannelCredentials.Insecure);
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • Thank you for your contribution! It didn't solve the issue though, unfortunatly. Please see the queastion for the additional infor I added – Q-bertsuit Sep 17 '20 at 10:10
  • 1
    @Q-bertsuit with the edit, it looks like you simply haven't told Kestrel to use http/2, which is required - kinda like here: https://github.com/protobuf-net/protobuf-net.Grpc/blob/main/examples/pb-net-grpc/Server_CS/Program.cs#L20 – Marc Gravell Sep 17 '20 at 10:12
  • I tried that, but still got an error. Please see edit. ThankS1 – Q-bertsuit Sep 17 '20 at 11:39
  • 1
    @Q-bertsuit a 307 is a redirect, which suggests a config problem; I can't debug a config problem without being able to repro it, but *generally* gRPC *just works*; is what you're doing perhaps available as a github repo that we can *actually run*? – Marc Gravell Sep 17 '20 at 12:12
  • I created a repo with the issue reproduced. Please see the top of the post. Thanks again! – Q-bertsuit Sep 18 '20 at 09:03
  • I got it working by following this answere https://stackoverflow.com/a/61121433/1235291 – Q-bertsuit Sep 18 '20 at 10:08
  • @Q-bertsuit you should answer your post. I overlooked for a long time that this post actually has an answer to my issue because the answer is hidden away in comment. It is not easy to spot that a solution actually has been found – Nulle Feb 14 '21 at 12:24
0

I got it working by following this answer

Q-bertsuit
  • 3,223
  • 6
  • 30
  • 55