Introduction
In this article we will look at gRPC and how to implement gRPC solutions using Visual Studio 2019. gRPC is a high performance, open-source and easy to use RPC framework developed by Google. It has gained lots of popularity as it can be used across platforms and has lots of features for easy documentation. Visual Studio 2019 includes a template for building gRPC server applications, and we will look at building a simple gRPC server application. We will also build a client application to consume the API that is available on the server.
Difference between gRPC and Web API
One question that might come to mind immediately is, what is the difference between Web API of the .NET world and gRPC of the Google world. Although both are cross platform and open source the main difference is that requests for Web API are in a text format which are human readable whereas gRPC messages are encoded by Protobuf by default. Protobuf or Protocol buffers is a very efficient way to transfer information and the binary format is not human readable.
Building the gRPC server
We will be using Visual Studio 2019 to build the gRPC server. Create a new project and follow the steps below,


You can delete the existing “greet.proto” file and the service associated with it. Then add the following employee.proto file to the Protos folder,
- syntax = "proto3";
- option csharp_namespace = "GrpcEmployee";
- package employee;
- // The greeting service definition.
- service Employee {
- rpc GetEmployeeInfo (EmployeeInfoRequest) returns (EmployeeInfoResponse);
- }
- // The request message containing the employee ID.
- message EmployeeInfoRequest {
- int32 ID = 1;
- }
- // The response message containing the employee data.
- message EmployeeInfoResponse {
- int32 ID = 1;
- string FirstName = 2;
- string LastName = 3;
- string Address = 4;
- string PhoneNumber = 5;
- string EmailAddress = 6;
- }
Ensure that the property settings of this file are as below,

Also, add a class “EmployeeService” under services as below,
- using System.Threading.Tasks;
- using Grpc.Core;
- using Microsoft.Extensions.Logging;
- namespace GrpcEmployee
- {
- public class EmployeeService : Employee.EmployeeBase
- {
- private readonly ILogger<EmployeeService> _logger;
- public EmployeeService(ILogger<EmployeeService> logger)
- {
- _logger = logger;
- }
- public override Task<EmployeeInfoResponse> GetEmployeeInfo(EmployeeInfoRequest request, ServerCallContext context)
- {
- return Task.FromResult(new EmployeeInfoResponse
- {
- ID = 100,
- FirstName = "John",
- LastName = "Doe",
- Address = "Toronto",
- PhoneNumber = "123-123-1234",
- EmailAddress = "[email protected]"
- });
- }
- }
- }
Ensure the project file matches the below,




David CorbinPosted Dec 2, 2021, 2:36 PM
Have you found a way to "import" .proto files so that things can be nicely factored/shared... I can't seem to get the pathing right for a build within Visual Studio.