Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Microservices Communication in .NET Using gRPC

You're reading from   Microservices Communication in .NET Using gRPC A practical guide for .NET developers to build efficient communication mechanism for distributed apps

Arrow left icon
Product type Paperback
Published in Feb 2022
Publisher Packt
ISBN-13 9781803236438
Length 486 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Fiodar Sazanavets Fiodar Sazanavets
Author Profile Icon Fiodar Sazanavets
Fiodar Sazanavets
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Section 1: Basics of gRPC on .NET
2. Chapter 1: Creating a Basic gRPC Application on ASP.NET Core FREE CHAPTER 3. Chapter 2: When gRPC Is the Best Tool and When It Isn't 4. Chapter 3: Protobuf – the Communication Protocol of gRPC 5. Section 2: Best Practices of Using gRPC
6. Chapter 4: Performance Best Practices for Using gRPC on .NET 7. Chapter 5: Applying Versioning to the gRPC API 8. Chapter 6: Scaling a gRPC Application 9. Section 3: In-Depth Look at gRPC on .NET
10. Chapter 7: Using Different Call Types Supported by gRPC 11. Chapter 8: Using Well-Known Types to Make Protobuf More Handy 12. Chapter 9: Securing gRPC Endpoints in Your ASP.NET Core Application with SSL/TLS 13. Chapter 10: Applying Authentication and Authorization to gRPC Endpoints 14. Chapter 11: Using Logging, Metrics, and Debugging in gRPC on .NET 15. Assessments 16. Other Books You May Enjoy

Running a gRPC service on Mac

At the time of writing, you cannot apply TLS while running gRPC Server on Mac. This is because of missing Application Layer Protocol Negotiation (ALPN) support on the operating system. So, to make it work, you need to enable HTTP access to the server instead of HTTPS.

Configuring server-side components

First, you need to enable an unencrypted endpoint HTTP/2 endpoint inside your application. To do so, open the Program.cs file inside your gRPC server project. Then, add the following using statement on top of it:

using Microsoft.AspNetCore.Server.Kestrel.Core;

Then, inside the Main method (which is the entry point into the application), add the following block of code inside the call to the ConfigureWebHostingDefaults method:

webBuilder.ConfigureKestrel(options =>
{
    options.ListenLocalhost(<port number>, o => o.Protocols =
    HttpProtocols.Http2);
});

Replace <port number> with the actual port number of the HTTP endpoint, which can be found under the applicationUrl key in the launchSettings.json file, which is located in the Properties folder of the project.

Once you've done this, your application will be ready to accept insecure HTTP/2 requests on the specified port number.

Modifying the client-side configuration

Because TLS doesn't work on the server, you won't be able to send requests to it via the HTTPS endpoint. So, while creating the GrpcChannel object in the client application, you will need to pass the HTTP URL into it. The specific URL can be found under the applicationUrl key in the launchSettings.json file, which is located in the Properties folder of the gRPC server project.

You have been reading a chapter from
Microservices Communication in .NET Using gRPC
Published in: Feb 2022
Publisher: Packt
ISBN-13: 9781803236438
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime