Consuming gRPC services in ASP.NET Core applications
In the previous section, we learned how to create console applications to consume gRPC services. In this section, we will integrate gRPC services into ASP.NET Core applications. We will reuse the gRPC services we created in the previous section, and we will create a new ASP.NET Core application to consume the gRPC services.
To get started with the steps outlined in this section, begin with the GrpcDemo-v3
folder of the source code. The complete code for this section can be found in the GrpcDemo-v4
folder.
In the console applications, we used the GrpcChannel
class to create a gRPC channel, after which we used the gRPC channel to create a gRPC client, as shown in the following code:
using var channel = GrpcChannel.ForAddress("https://localhost:7179");var client = new Contact.ContactClient(channel);
In ASP.NET Core applications, a better way to create a gRPC client is to use the IHttpClientFactory
interface with...