• 大小: 2.44MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-09-07
  • 语言: C#
  • 标签: asp.net  grpc  restful  

资源简介

aspnet core 5.0 grpc 双向认证, swagger启用, restful api

资源截图

代码片段和文件信息

using System;
using System.Net.Http;
using System.Threading.Tasks;
using grpcserver;
using Grpc.Net.Client;
using System.Security.Cryptography.X509Certificates;
using System.Security.Authentication;

namespace grpcclient
{
    class Program
    {
        static void Main(string[] args)
        {
           var handler = new HttpClientHandler()
            {
                SslProtocols = SslProtocols.Tls12
                ClientCertificateOptions = ClientCertificateOption.Manual
                ServerCertificateCustomValidationCallback = (message cer chain errors) =>
                {
                    return chain.Build(cer);
                }
            };
            var path = AppDomain.CurrentDomain.baseDirectory + “cert\\client.pfx“;
            var crt = new X509Certificate2(path “123456789“);
            handler.ClientCertificates.Add(crt);

             var channel = GrpcChannel.ForAddress(“https://localhost:5001“new GrpcChannelOptions{HttpHandler=handler});
            var client =  new Greeter.GreeterClient(channel);
            var reply =  client.SayHello( new HelloRequest { Name = “GreeterClient“ });
            Console.WriteLine(“Greeting: “ + reply.Message);
            ///
            Console.WriteLine(“http start................“);
             var httphandler = new HttpClientHandler();
             httphandler.ServerCertificateCustomValidationCallback=HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
             var httpclient=new HttpClient(httphandler);
            var ret= httpclient.GetStringAsync(“http://localhost:5000/v1/greeter/gavin“).Result;
            Console.WriteLine(ret);
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2021-01-03 13:58  asp.netgrpccert\
     目录           0  2021-01-03 09:37  asp.netgrpccert\.vs\
     目录           0  2021-01-03 09:37  asp.netgrpccert\.vs\asp.netgrpc\
     目录           0  2021-01-03 09:37  asp.netgrpccert\.vs\asp.netgrpc\DesignTimeBuild\
     文件      126710  2021-01-03 09:37  asp.netgrpccert\.vs\asp.netgrpc\DesignTimeBuild\.dtbcache.v2
     目录           0  2021-01-03 09:37  asp.netgrpccert\.vs\asp.netgrpc\v16\
     文件       37888  2021-01-03 09:37  asp.netgrpccert\.vs\asp.netgrpc\v16\.suo
     目录           0  2021-01-03 09:37  asp.netgrpccert\.vscode\
     文件        1437  2021-01-03 08:49  asp.netgrpccert\.vscode\launch.json
     目录           0  2021-01-03 09:37  asp.netgrpccert\.vscode\solution-explorer\
     文件          89  2021-01-03 08:43  asp.netgrpccert\.vscode\solution-explorer\class.cs-template
     文件          28  2021-01-03 08:43  asp.netgrpccert\.vscode\solution-explorer\class.ts-template
     文件         110  2021-01-03 08:43  asp.netgrpccert\.vscode\solution-explorer\class.vb-template
     文件          30  2021-01-03 08:43  asp.netgrpccert\.vscode\solution-explorer\default.ts-template
     文件          88  2021-01-03 08:43  asp.netgrpccert\.vscode\solution-explorer\enum.cs-template
     文件          93  2021-01-03 08:43  asp.netgrpccert\.vscode\solution-explorer\interface.cs-template
     文件          32  2021-01-03 08:43  asp.netgrpccert\.vscode\solution-explorer\interface.ts-template
     文件        1329  2021-01-03 08:43  asp.netgrpccert\.vscode\solution-explorer\template-list.json
     文件         574  2021-01-03 08:43  asp.netgrpccert\.vscode\solution-explorer\template-parameters.js
     文件        1250  2021-01-03 08:49  asp.netgrpccert\.vscode\tasks.json
     文件        2853  2021-01-03 08:50  asp.netgrpccert\asp.netgrpc.sln
     目录           0  2021-01-03 13:58  asp.netgrpccert\cert2\
     文件        1286  2021-01-02 12:42  asp.netgrpccert\cert2\client.crt
     文件        1076  2021-01-02 12:42  asp.netgrpccert\cert2\client.csr
     文件        1773  2021-01-02 12:41  asp.netgrpccert\cert2\client.key
     文件        2493  2021-01-02 12:42  asp.netgrpccert\cert2\client.pfx
     文件       10988  2021-01-02 12:09  asp.netgrpccert\cert2\openssl.cfg
     文件        1250  2021-01-02 12:27  asp.netgrpccert\cert2\root.crt
     文件        1026  2021-01-02 12:27  asp.netgrpccert\cert2\root.csr
     文件        1781  2021-01-02 12:27  asp.netgrpccert\cert2\root.key
     文件          42  2021-01-02 12:42  asp.netgrpccert\cert2\root.srl
............此处省略151个文件信息

评论

共有 条评论