I followed the instructions at:
https://docs.microsoft.com/en-us/aspnet/core/tutorials/grpc/grpc-start?view=aspnetcore-3.1&tabs=visual-studio
to create a
you can configure the .Net core grpc server on insecure through config
There are 2 ways,
{
"profiles": {
"DemoService": {
"commandName": "Project",
"launchBrowser": false,
"applicationUrl": "http://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Or
"Kestrel": {
"EndpointDefaults": {
"Protocols": "Http2"
},
"EndPoints": {
"Http": {
"Url": "http://localhost:5001"
}
}
}
Over SSL or not, you need to turn on Http2 in ASP.NET Core server. So in appsettings.json, do this.
"Kestrel": {
"EndpointDefaults": {
"Protocols": "Http2"
}
Insecure .NET Framework Client + ASP.NET Core Server
app.UseHttpsRedirection() and app.UseHsts() in the StartUp class ConfigureServices(IApplicationBuilder app);var channel = new Channel("localhost", 5001, secureCredentials);
Secure SSL connection .NET Framework Client + ASP.NET Core Server
I got it working with SSL port by using the same Server's certificate in .pem format in the client.
SslCredentials secureCredentials = new SslCredentials(File.ReadAllText("certificate.pem"));
var channel = new Channel("localhost", 5001, secureCredentials);
A bit of explanation. An ASP.NETCore template in VS 2019 uses a development certificate
with pfx file at %AppData%\ASP.NET\Https\ProjectName.pfx and
password = %AppData%\Microsoft\UserSecrets\{UserSecretsId}\secrets.json {:Kestrel:Certificates:Development:Password} Value
You can get the UserSecretsId id from the ProjectName.csproj. This will be different for each ASP.NET Core Project.
I used the below command to convert the pfx + password combination to a certificate.pem file.
openssl pkcs12 -in "<DiskLocationOfPfx>\ProjectName.pfx" -out "<TargetLocation>\certifcate.pem" -clcerts
This will prompt for the pfx password. Use the password from the above secrets.json.
Give some passphrase for the certificate.pem to be generated(At least 4 letter).
Copy this cerificate.pem for the gRPC .NET Framework client to access and use in
SslCredentials secureCredentials = new SslCredentials(File.ReadAllText("<DiskLocationTo the Folder>/certificate.pem"))
var channel = new Channel("localhost", 5001, secureCredentials);
Note that port 5001 I used is the SSL port of my ASP.NET Core application.
For Production Scenarios
Use a valid certificate from certificate signing authority and use same certificate in ASP.NET Core Server and .NET Framework client as pfx and pem respectively.