I'm posting this answer for the sake of next person looking for the solution.
I have posted my solution in similar use case question in SO after I got it working here and here
-- Below is copied from My own answer.
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
- ASP.NET Core Server
- Remove
app.UseHttpsRedirection()
and app.UseHsts()
in the StartUp
class ConfigureServices(IApplicationBuilder app)
;
- Expose the insecure port, typically 80 or 5000 during development.
- Use the code below to create insecure channel in .NET Framework client.
var channel = new Channel("localhost", 5001, ChannelCredentials.Insecure);
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.