Issue
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. 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.
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. 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.
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.
Solution
You could try to use Grpc.Core
or gRPC-Web
as it is mentioned in the 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.
And you may refer to https://stackoverflow.com/a/60362990/10768653.
Answered By - Leo Zhu - MSFT
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.