I have a server on the platform .Net Framework 4.8, which contains a gRPC service with SslServerCredentials for transport security, with self signed certificate. The certificate common name (CN) is LOCALHOST. So, I have some clients on the platform .Net Core 2.1 that works fine with this server. Now, I have started developing a new client on the platform .Net 5, and ran into some problems. Client code:
var key = GetServerKey();
var opt = new GrpcChannelOptions
{
MaxReceiveMessageSize = int.MaxValue,
MaxSendMessageSize = int.MaxValue
};
GrpcChannel channel;
var buf = GetBytesFromCrt(key);
var cert = new X509Certificate2(buf);
var handler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
};
handler.ClientCertificates.Add(cert);
var httpClient = new HttpClient(handler);
opt.HttpClient = httpClient;
channel = GrpcChannel.ForAddress($"https://{server}", opt);
var _grpcClient = new AppWinServiceGrpc.AppWinServiceGrpcClient(channel);
var res = _grpcClient.Ping(new PingRequest { Ping = "1" });
On other computers with Windows 10 and Windows 2016 Server, everything works correctly. On my computer with Windows 10, I get errors. When I specify the server IP address, the error is "Received an unexpected EOF or 0 bytes from the transport stream". In .Net Core 2.1 project I added parameter grpc.ssl_target_name_override = "LOCALHOST". In the project .Net 5 I didn't find where to add it.
When I specify the server as localhost instead of an IP address, the error is "Requesting HTTP version 2.0 with version policy RequestVersionOrHigher"
That is, the problem is clearly that something is missing on my computer. But what is missing, and what needs to be done to fix it, is unclear...