.Net Core 3.0 gRPC deployment issues resolved

Foreword

  .Net Core3.0 finally come to the party came. 3.0 adds many things, but also there have been many changes. Today we are looking at is the use of gRPC in 3.0 and the problems encountered. gRPC now can be very simple and convenient to use in the .Net Core, today I also tried it, but unfortunately encountered a number of obstacles. We take a look at what is the problem now.

gRPC Introduction

  gRPC google open source is a high performance, cross-language framework RPC based protocol HTTP2, ProtoBuf defined using IDL.

  advantage:

    1. Modern high-performance lightweight RPC framework
    2. Priority API development agreement, default protocol buffer, allows nothing to do with language
    3. Tools can be achieved in multiple languages
    4. protobuf binary serialization, good performance / high efficiency
    5. Based Http2.0

  In ASP.NET Core 3.0 in gRPC there are many articles were introduced, I also read these articles to learn undertaken. It also may have to go looking for.

Deployment Issues

  Follow the tutorial step by step article uses gRPC in ASP.NET Core 3.0 is created in the project, writing code. There is a process to go down it is to fill the gap. We began testing locally When you write. Start and end up service. In running the client. See the message on the client returned. Success. Successfully the first time, it really is more simple. Wherein there are two points to be noted that because the gRPC 3.0 is used based on the Http2.0. And it requires HTTPS, though that does not explicitly requiring the use of HTTPS, but for security in the browser are required to achieve the HTTPS, so now the HTTP / 2 and HTTPS basically couple.

  So we will be a bomb in the box when running locally, asking if we trust certificates. Now I question the will and the related. Local works just fine. I wanted to try to move up the server okay. The results took up the server is up and running, the results of the client running on the error.

Unhandled exception. System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.

 ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

 

 

solution

1, modify the https to http (no, wrong)

  The error I am a bit puzzled, I first check the environment, found that right. Little wonder. Then look at is the connection failed. I will try to modify https to http. The result was wrong. This method was abandoned. (Causes the client and server SSL After modifying / TLS configuration does not match ..Net Core clients must use https in the address to the correct server using a secure connection)

2, trust certificate (possible)

  Watch carefully for errors, and finally found marked as invalid certificate. This is prompted to think of our pop we trust certificates at the time of the first run locally. If that is the relationship. According to this way I want to go. Find how to install ASP.NET Core HTTPS development certificate. Then we try again, and sure enough on it.

dotnet dev-certs https --trust

 

3, ignore invalid certificate (possible)

  Later they found a solution to the problem since it is caused by an invalid certificate, you can ignore the invalid certificate is not it? Then we replace servers, continue to try. Add the code in the code ignore invalid certificate. Then try again to find also possible. It should be noted however that this ignores invalid certificate or replaced by a valid certificate to use in the development process, change to the production environment

           

        var httpClientHandler = new HttpClientHandler();
            // Return `true` to allow certificates that are untrusted/invalid
            httpClientHandler.ServerCertificateCustomValidationCallback =
         HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
            var httpClient = new HttpClient(httpClientHandler);
 

            var channel = GrpcChannel.ForAddress("https://localhost:5001",new GrpcChannelOptions { HttpClient = httpClient });
            var client = new Greeter.GreeterClient(channel);

 

 

to sum up

  Match to keep the client and server when we use when used gRPC .Net Core 3.0, you need to pay attention to the SSL / TLS configurations, based HTTP2.0, using https connection. Issue a certificate that is appears solved in the development environment, in full production environment, we still need to use a valid certificate.


    Ordinary life of ordinary use to treat heart, your life will be more exciting. 

  Welcome to scan the next Fanger Wei code, and learn about more knowledge of it!

  

Guess you like

Origin www.cnblogs.com/hulizhong/p/11586053.html