I am trying to get a HTTP2 serverside stream up and running using an .NET 5.0 server, and a .NET Framework client. When using a framework client i have to use the WinHttpHander according to Microsofts Documentation(https://docs.microsoft.com/en-us/aspnet/core/grpc/netstandard?view=aspnetcore-5.0). When using the WinHttpHandler with a X509Certificate i always get the same error. The error seems to come only when using a certificate, which seems to be needed for Http2 with gRPC.
ArgumentException: Illegal characters in path.
I have tried several ways to add the certificate, using X509Certificate.Import, X509Certificate.CreateFromCertFile, X509Certificate.CreateFromSignedFile, and X509Certificate.Add, and they all give me the same error.
The client connection is made with following procedure (Code is F#)
let cacert = File.ReadAllText(@"ca.crt");
let clientCert = File.ReadAllText(@"client.crt");
let clientkey = File.ReadAllText(@"client.key");
let X509Cert = X509Certificate.CreateFromSignedFile(clientCert)
let handler = new WinHttpHandler()
handler.ClientCertificates.Add(X509Cert) |> ignore
handler.ServerCertificateValidationCallback <- fun msg clientcert cacert e -> true
let httpclient = new HttpClient(handler)
let channelOptions = GrpcChannelOptions(HttpClient = httpclient)
let channel = GrpcChannel.ForAddress("https://127.0.0.1:5001",channelOptions)
let client = DeFactoGrpc.EventSubscriberService.EventSubscriberServiceClient(channel)
If needed the server is made with following procedure (Code is F#)
let cacert = File.ReadAllText(@"ca.crt");
let servercert = File.ReadAllText(@"server.crt");
let serverkey = File.ReadAllText(@"server.key");
let certificatePair = new KeyCertificatePair(servercert, serverkey);
let certList = new System.Collections.Generic.List<KeyCertificatePair>()
certList.Add(certificatePair)
let server = new Server()
server.Services.Add(EventSubscriberService.EventSubscriberServiceMethodBinder.BindService(new EventSubscriber()))
server.Ports.Add(new ServerPort("localhost", 5001,SslServerCredentials(certList,cacert,false)))
|> ignore