Hi together,
we have a .net461 LegacyApp (as a Client) and trying to get a gRPC call to a .netcore Kestrel grpc Server App.
For the new one, of course we using dotnet-grpc. (Grpc.AspNetCore nupkg)
For the LegacyApp we trying the google core lib(s). (Grpc.Core nupkg)
Looking basicly like that:
Server
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseUrls("https://1.2.3.4:3333");
webBuilder.UseStartup<Startup>();
});
}
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddGrpc();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService<MyGrpcService>();
});
}
}
Client
var channel = new Channel("1.2.3.4", 3333, ChannelCredentials.Insecure);
var client = new MyGrpcServiceClient(channel);
Console.WriteLine(client.Echo("123"));
Unfortunately, we have not yet managed to get a successful call.
When using "google to google" or "grpc-dotnet to grpc-dotnet" all works fine.
Is it even possible? If so, what are we doing wrong?
Thank you kl1mm
Hi!
Can you share errors you got?
By the way it's better to use Grpc.Net.Client & Grpc.Net.ClientFactory but they target .NET Standard 2.1 which is not supported by .NET 4.6.1 (max 2.0).
https://docs.microsoft.com/en-us/dotnet/standard/net-standard
@JamesNK Any reason why these libraries don't target .NET Standard 2.0 ?
Your ASP.NET Core server is setup with TLS (HTTPS). Your Grpc.Core client is using ChannelCredentials.Insecure which means no TLS. You need to update one of them to match the other.
Any reason why these libraries don't target .NET Standard 2.0 ?
Features were added in 2.1 (trailers) that are required.
Hi JamesNK, hi AnthonyGiretti
thanks for your advice. I managed to get it to work 馃憤
Looks basically like that:
DoGrpcCall(new Channel("hostname:3333", ChannelCredentials.Insecure), "via http");
var sslCredentials = new SslCredentials(File.ReadAllText("certificate.pem"));
DoGrpcCall(new Channel("hostname:4444", sslCredentials), "via https");
...
webBuilder.ConfigureKestrel(options =>
{
options.Listen(IPAddress.Any, 3333, listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http2;
});
options.Listen(IPAddress.Any, 4444, listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http2;
listenOptions.UseHttps("certificate.pfx", "1234");
});
});
...
There remains a small question, although here may be the wrong place:
Do you know how to configure the the Kestrel-Server to use the SslCredentials.Insecure ? So far I haven't been able to find out.
Thanks again for your help, best regards
kl1mm
Since you are using https in your configuration you can鈥檛 do that.
The only thing you can do is to choose your TLS version : https://stackoverflow.com/questions/54150473/how-to-implement-tls-1-2-in-asp-net-core-2-0
Do you know how to configure the the Kestrel-Server to use the SslCredentials.Insecure ?
You already are. Port 3333 doesn't have a TLS certificate. That's the same as SslCredentials.Insecure.
Did this not work?
DoGrpcCall(new Channel("hostname:3333", ChannelCredentials.Insecure), "via http");
It works, but I thought SslCredentials.Insecure is different from ChannelCredentials.Insecure
They're the same. SslCredentials.Insecure is inherited from ChannelCredentials.
Most helpful comment
Your ASP.NET Core server is setup with TLS (HTTPS). Your Grpc.Core client is using
ChannelCredentials.Insecurewhich means no TLS. You need to update one of them to match the other.Features were added in 2.1 (trailers) that are required.