Xamarin 表单和 gRPC:服务器返回无效或无法识别的响应

Xamarin forms and gRPC: The server returned an invalid or unrecognized response

我正在尝试从 gRPC 服务获取响应,但是当我从 Xamarin 应用程序进行调用时,我收到服务器返回无效或无法识别的响应的错误。但是,如果我使用 WPF 客户端,它使用与 Xamarin 应用程序相同的 gRPC 客户端库,它会按预期工作,我会收到服务的响应。

服务代码是这样的:

            webBuilder.ConfigureKestrel(options =>
            {
                options.Listen(IPAddress.Any, 5001, listenOptions =>
                {
                    listenOptions.Protocols = HttpProtocols.Http2;
                    listenOptions.UseHttps("server.pfx", "1111");
                });
            });
            webBuilder.UseStartup<Startup>();

客户端库:

        HttpClientHandler miHandler = new HttpClientHandler();

        miHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;

        GrpcChannelOptions misOpciones = new GrpcChannelOptions() { HttpHandler = miHandler };

        var miChannel = GrpcChannel.ForAddress("https://192.168.1.134:5001", misOpciones);

我做错了什么?起初我以为是因为从android开始我不能用http,所以我需要https,但是现在我用的是https。确实我忽略了来自服务器的任何证书,这可能是原因吗?但是错误消息会与 SSL 或类似的东西有关,而不是告诉响应无法识别。

谢谢。

编辑:在托管该服务的控制台应用程序中,我失败了:HTTP/2 over TLS was not needed on an HTTP/2-only endpoint.

您可以尝试使用 Grpc.CoregRPC-Web,因为它在 documentation.

中提到

Calling gRPC over HTTP/2 with Grpc.Net.Client is currently not supported on Xamarin. We are working to improve HTTP/2 support in a future Xamarin release. Grpc.Core and gRPC-Web are viable alternatives that work today.

你可以参考