From 913e9ad6c2196e329487e1897ef4e846ae3d5b01 Mon Sep 17 00:00:00 2001 From: Michal Date: Tue, 12 Oct 2021 21:46:27 +0200 Subject: [PATCH] When testing GRPC on local environment we might get: --> Calling GRPC Service https://localhost:5001 --> Couldnot call GRPC Server Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: The SSL connection could not be established, see inner exception. AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot", DebugException="System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot We can avoid it by adding that to PlatformDataClient --- .../SyncDataServices/Grpc/PlatformDataClient.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CommandsService/SyncDataServices/Grpc/PlatformDataClient.cs b/CommandsService/SyncDataServices/Grpc/PlatformDataClient.cs index bcf1b80..6aeab08 100644 --- a/CommandsService/SyncDataServices/Grpc/PlatformDataClient.cs +++ b/CommandsService/SyncDataServices/Grpc/PlatformDataClient.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Net.Http; using AutoMapper; using CommandsService.Models; using Grpc.Net.Client; @@ -22,7 +23,15 @@ public PlatformDataClient(IConfiguration configuration, IMapper mapper) public IEnumerable ReturnAllPlatforms() { Console.WriteLine($"--> Calling GRPC Service {_configuration["GrpcPlatform"]}"); - var channel = GrpcChannel.ForAddress(_configuration["GrpcPlatform"]); + + var httpHandler = new HttpClientHandler(); + //allow certificates that are untrusted/invalid + httpHandler.ServerCertificateCustomValidationCallback = + HttpClientHandler.DangerousAcceptAnyServerCertificateValidator; + + var channel = GrpcChannel.ForAddress(_configuration["GrpcPlatform"], + new GrpcChannelOptions { HttpHandler = httpHandler }); + var client = new GrpcPlatform.GrpcPlatformClient(channel); var request = new GetAllRequest();