I have created a gRPC service in .NET Core which needs to be used from a legacy WPF application running on .NET 4.7.2. The existing WPF application is huge and can\'t be con
I finally got a working solution for this problem with:
The main problem was to find a solution to accept a self-signed SSL server certificate from a remote client, which is a mandatory for our scenario.
The server gets a generated certificate using a solution like provided here (solution also works with any valid certificate): https://gist.github.com/mivano/356d4f0354d997370e3c2e62809cdeef
Important thing to mention here: the DNS or IP of the server is verified by the client so it has to be part of the certificate.
gRPC Server was configured this way (could also be achieved through .appsettings.json):
webBuilder.ConfigureKestrel(
options =>
{
options.Listen(
IPAddress.Any,
<your port>,
listenOptions =>
{
listenOptions.UseHttps("<your.pfx path>", "<your passphrase>");
listenOptions.Protocols = HttpProtocols.Http2;
});
});
gRPC Client:
openssl pkcs12 -in "<pfx path>.pfx" -out "<pem path>.pem" -clcerts
How do you create a gRPC client in .NET Framework?
Channel:
var channelCredentials = new SslCredentials(
File.ReadAllText("<path to pem>.pem"), null, verifyPeerCallback => true);
var serviceChannel = new Channel("<DnsName from cert", <port>, channelCredentials);
var serviceProxy = new GrpcService.GrpcServiceClient(serviceChannel );
The client can also be implemented to dynamically download the certificate from the server using a regualar HttpClient.Get with a proper HttpClientHandler and attached ServerCertifacteCustomValidationCallback. The pem has to be created in memory before the service channel creation: https://github.com/grpc/grpc/issues/8978#issuecomment-283469676
As mm8 stated, Grpc.Core is the predecessor to the grpc that is baked into .Net Core grpc-donet. In general they are very similar.
I just went thru this process of converting a medium sized WPF Framework app to net core with grpc replacing out WCF. It has been a learning curve but the issues were not in the WPF area as much as trying to produce a standard way of passing data the way I wanted.
If there is interest I can produce a small book on my solution.