Ai
1 Star 0 Fork 0

hardstylewyl/GRPC_Samples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Program.cs 963 Bytes
一键复制 编辑 原始数据 按行查看 历史
hardstylewyl 提交于 2025-01-08 00:07 +08:00 . 未实现grpc使用https证书
using System.Security.Cryptography.X509Certificates;
using _10GrpcServer;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using GreeterClient = _10GrpcServer.Greeter.GreeterClient;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddGrpcClient<GreeterClient>(x => { x.Address = new Uri("https://localhost:5001"); })
.ConfigureChannel(x =>
{
x.HttpHandler = CreateHttpHandler();
});
var app = builder.Build();
using var scope = app.Services.CreateScope();
var client = scope.ServiceProvider.GetRequiredService<GreeterClient>();
var reply = await client.SayHelloAsync(new HelloRequest { Name = "Grpc" });
Console.WriteLine(reply.Message);
static HttpClientHandler CreateHttpHandler()
{
var handler = new HttpClientHandler();
var clientCertificate = X509CertificateLoader.LoadPkcs12FromFile("Certs/hardstyle.pfx", "pass1234");
handler.ClientCertificates.Add(clientCertificate);
return handler;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hardstylewyl/grpc_samples.git
git@gitee.com:hardstylewyl/grpc_samples.git
hardstylewyl
grpc_samples
GRPC_Samples
master

搜索帮助