.Net Core 3.0 has been launched last month and one of the major features of it is gRPC. Let’s have a detailed discussion on how to get started with gRPC using C# and .Net Core. Let’s divide our article into the following sections,
Agenda
- What is GRPC
- GRPC Vs REST
- Creating GRPC Service
- Creating GRPC Client
- WCF to GRPC
- Conclusion
What is gRPC
According to official blog “GRPC is a open source high performance RPC framework that can run in any environment, it can efficiently connect services across data centers with support of load balancing, tracing and authentication.” Mostly gRPC is used for connecting polyglot services in microservices architecture, connecting mobile devices, browser clients to the services
Grpc has two parts the -- gRPC protocol and data serialization. By default gRPC uses Protobuf for the serialization and protocol is based on Http2 which provides a lot of advantages over traditional Http1.x
GRPC vs REST
REST has been one of the concrete pillars of the web programming recently, but the emergence of the gRPC has put some challenge before REST. The below tables explain the differences between them,
|
Parameter
|
REST
|
gRPC
|
|
Serialization
|
JSON/XML
|
protobuf
|
|
Protocol
|
HTTP/1.1
|
HTTP/2.0
|
|
Browser Support
|
Yes
|
No
|
|
Data Exchange
|
Resources and Verbs
|
Messages
|
|
Request-Response Model
|
Only supports Request Response as based on Http/1.1
|
Supports All Types Of Streaming as based on Http/2
|
|
Payload Exchange Format
|
Serialization like JSON/XML
|
Strong Typing
|
Creating GRPC Service
As we are good with the basics, for now, let’s move and see how we can create the Service, and later let’s see how we can consume that service into the client. To get started with the service we need to have a few initial things as follows
- Visual Studio 2019
- .NET Core SDK 3.1
Once you have this we can follow the following steps to create our first service
Add New Project and Select the GRPC Service as a new project

In our case, we are adding a Project with name ToDoGrpcService, when we will add the Project we will have the following Structure,

Our project will be added with the default Greet service and One Default greet. Proto File.
In this Project, we are going to create our first To-do. Grpc Service for that first we need to add the proto file like below.
Right Click on Protos Folder -> Add New Item -> Select ProtoBuff File and name it "ToDo" like below,

Creating ProtoBuff Service Contract and Schema
Grpc uses Proto File to define the service contracts and it also contains the schema for the data which will be sent across between the services. Our ToDo service will have the following code,
- syntax = "proto3";
- option csharp_namespace = "ToDoProtos";
- service ToDoService{
- rpc getToDoItem(google.protobuf.Empty) returns (ToDoModel);
- }
- message ToDoModel{
- string Title=1;;
- string Description=2;
- bool status=3;
- }
Code Explanation
- The first line specifies the version of Protobuff used in the programs; i.e. Proto3
- The second line specifies the Namespace under which this service will be created
- The next section specifies the actual service name and the Method into the Service. In our case our service is ToDoService and we have getToDoItem Method with empty parameter and returns the ToDoModel
- The last section is the actual data which will be returned from the service
Creating Server
Once we are done with adding the proto buff file we are ready to create the server. In this server we will use the automatically generated code from the protobuff file. We can stub out the functionality over the code which handles the communication and serialization.
To generate the code from the protobuf file we need to make the changes in the .csproj file of our project and add lines like below,

Implementing the Service
The next step in creating a service is to create a class that will be inherited from the above-generated class and implement the service contract that we have defined in the protobuff file above. Once implemented it will look like below


Joseph RozarioPosted Nov 27, 2019, 4:16 AM
Nice explanation
Hamid KhanPosted Oct 31, 2019, 2:23 AM
Good explanation...…………...
Ano MepaniPosted Oct 27, 2019, 6:12 AM
Nice arricle. I see for just simple hello world app we need to do lots of stuff and have other knowledge as well. So, What is purpose of Grpc? Where it will be used in real world use case?
Pankajkumar PatelPosted Oct 22, 2019, 11:07 PM
Nice article
Abhishek MishraPosted Oct 22, 2019, 1:40 PM
Pretty interesting
Sourav Kumar DasPosted Oct 22, 2019, 12:22 AM
Nice Article Sir.