Tutorial: Get started with gRPC service in ASP.NET Core

By John Luo

This tutorial teaches the basics of building a gRPC service on ASP.NET Core.

At the end, you'll have a gRPC service that echoes greetings.

View or download sample code (how to download).

In this tutorial, you:

  • Create a gRPC service.
  • Run the gRPC service.
  • Examine the project files.

Prerequisites

Create a gRPC service

  • From the Visual Studio File menu, select New > Project.

  • Create a new ASP.NET Core Web Application. new ASP.NET Core Web Application

  • Name the project GrpcGreeter. It's important to name the project GrpcGreeter so the namespaces will match when you copy and paste code. new ASP.NET Core Web Application

  • Select .NET Core and ASP.NET Core 3.0 in the dropdown. Choose the gRPC Service template.

    The following starter project is created:

    Solution Explorer

Run the service

  • Press Ctrl+F5 to run the gRPC service without the debugger.

    Visual Studio runs the service in a command prompt. The logs show that the service started listening on http://localhost:50051.

    new ASP.NET Core Web Application

The next tutorial will demonstrate how to build a gRPC client, which is required to test the Greeter service.

Examine the project files of the gRPC project

GrpcGreeter files:

  • greet.proto: The Protos/greet.proto file defines the Greeter gRPC and is used to generate the gRPC server assets. For more information, see Introduction to gRPC on ASP.NET Core.
  • Services folder: Contains the implementation of the Greeter service.
  • appSettings.json:Contains configuration data, such as protocol used by Kestrel. For more information, see Configuration in ASP.NET Core.
  • Program.cs: Contains the entry point for the gRPC service. For more information, see ASP.NET Core Web Host.
  • Startup.cs: Contains code that configures app behavior. For more information, see App startup in ASP.NET Core.

Test the service

Additional resources

In this tutorial, you:

  • Created a gRPC service.
  • Ran the gRPC service.
  • Examined the project files.