Overview
This article will do a brief introduction to the gRPC framework, then will see how gRPC services can be created with ASP.NET Core and how we can invoke these services from .NET Core applications.
Introduction
gRPC is a framework designed and introduced by Google and made an open-source project since 2015. This Framework enables Remote Procedure Calls (RPC) between services using HTTP/2 protocol with binary messages which are serialized/deserialized using Protocol Buffers a new binary protocol designed by Google for generating more compact messages such that it will use less CPU and more performance-oriented while transferring between two endpoints.
This Framework included in .NET Core since version 3.0 and provided with special gRPC services template in Visual Studio 2019 IDE.
gRPC uses proto files to define services and their message contracts information. These contracts will be serialized/de-serialized to binary messages by protocol buffer and pass through the HTTP/2 protocol.
Once the developer has written proto files with respective services and message contracts, the tooling library from the gRPC Framework will create strongly typed classes for services and POCO classes for message contracts in proto files. This way we can able to call the methods and variables defined in the proto file in other C# classes as we do in normal with other strongly typed C# classes.
Currently, gRPC services are most widely used in Microservice Architecture to communicate between loosely coupled services. Still, we are facing some issues while communicating from browser to services as most of the browsers are still working to include it in the near future.
Now we are good enough with understanding this new Framework and now we need to learn more on the practical side from the developer's eye by understanding creating and consuming the services in .NET Core.
Creating the gRPC Server
As gRPC Framework ships with ASP.NET Core 3.0 along with the gRPC service project template. It is a straightforward task to create it as follows.
Click Next Button and provide the service name as follows
Once the service is created we can see two folders
- Protos - this folder will contain all .proto files. As discussed in the introduction section, these files should contain all the services and message contracts in C# terminology, Interfaces, and POCO classes.
- Services - this folder will contain concrete strongly typed service classes which inherited from the services/interfaces declared in the proto file(s).
When we observe the packages list, we have 3 new packages which are related to gRPC, as follows:
- Google.Probuf contain necessary classes that define the data types which are supported while writing all message contracts in proto buffer files (i.e., *.proto files) and syntaxes.
- Grpc.Tools contain necessary classes for converting all services and message contracts to C# strongly typed interfaces and POCO classes.
- Grpc.AspNetCore.Server.ClientFactory contains necessary classes to manage the connections from its client(s).
Following is the default proto file (greet.proto) that will be provided when we create a new gRPCService project.
- syntax = "proto3";
- option csharp_namespace = "GrpcCustomerService";
- package greet;
- // The greeting service definition.
- service Greeter {
- // Sends a greeting
- rpc SayHello (HelloRequest) returns (HelloReply);
- }
- // The request message containing the user's name.
- message HelloRequest {
- string name = 1;
- }
- // The response message containing the greetings.
- message HelloReply {
- string message = 1;
- }
Let's understand it line by line. The first line will contain which syntax version does this file will follow. This is just like a C# version we use to provide.
Later we providing a namespace to be available on the file which will be generated by the gRPC tool when we build the application.

Join the conversation! Your thoughts help the community grow.