[英]Xamarin forms and gRPC: The server returned an invalid or unrecognized response
I am trying to get a response from the gRPC service but I get the error that the server returned an invalid or unrecognized response when I make the call from a Xamarin application.我正在尝试从 gRPC 服务获取响应,但是当我从 Xamarin 应用程序进行调用时,我收到服务器返回无效或无法识别的响应的错误。 However, if I use a WPF client, that use the same gRPC client library than the Xamarin application, it works as exepected, I get the response from the service.
但是,如果我使用 WPF 客户端,它使用与 Xamarin 应用程序相同的 gRPC 客户端库,它会按预期工作,我会从服务中获得响应。
The service code is this:服务代码是这样的:
webBuilder.ConfigureKestrel(options =>
{
options.Listen(IPAddress.Any, 5001, listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http2;
listenOptions.UseHttps("server.pfx", "1111");
});
});
webBuilder.UseStartup<Startup>();
Client library:客户端库:
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);
What I am doing wrong?我做错了什么? At first I thought it was because from android I couldn't use http, that I need https, but now I am using https.
起初我以为是因为从android我不能使用http,我需要https,但现在我使用的是http,但现在我使用的是https,但现在我使用的是http,但现在我使用的是https。 It is true that I am ignoring any certificate from the server, could it be this the reason for that?
确实,我忽略了来自服务器的任何证书,这可能是原因吗? But the error message it would be related with SSL or something like that, instead of telling that the response is not recognized.
但是错误消息将与 SSL 或类似的东西有关,而不是告诉响应无法识别。
Thanks.谢谢。
EDIT: in the console aplication that hosts the service, I get this fail: HTTP/2 over TLS was not negotiated on an HTTP/2-only endpoint.编辑:在托管服务的控制台应用程序中,我失败了:HTTP/2 over TLS 未在仅 HTTP/2 的端点上协商。
You could try to use Grpc.Core
or gRPC-Web
as it is mentioned in the documentation .您可以尝试使用文档中提到的
Grpc.Core
或gRPC-Web
。
Calling gRPC over HTTP/2 with Grpc.Net.Client is currently not supported on Xamarin.
Xamarin 目前不支持使用 Grpc.Net.Client 通过 HTTP/2 调用 gRPC。 We are working to improve HTTP/2 support in a future Xamarin release.
我们正在努力在未来的 Xamarin 版本中改进对 HTTP/2 的支持。 Grpc.Core and gRPC-Web are viable alternatives that work today.
Grpc.Core 和 gRPC-Web 是当今可行的替代方案。
And you may refer to https://stackoverflow.com/a/60362990/10768653 .您可以参考https://stackoverflow.com/a/60362990/10768653 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.