How to build gRPC applications in ASP.NET Core

0
168


gRPC is a Google-created, open source, schema-first remote procedure call (RPC) framework that takes advantage of HTTP/2 protocol to transport binary messages. These messages are serialized and deserialized using Protocol Buffers, a binary serialization protocol also from Google. gRPC takes advantage of Protocol Buffers as its Interface Definition Language (IDL).

This article presents an overview of gRPC and how we can work with it in ASP.NET Core. In this article we’ll introduce gRPC, discuss why we need it, and implement both a gRPC server and a gRPC client. 

[  ]

What is gRPC? 

Initially designed by Google, gRPC has become extremely popular for building distributed systems. gRPC supports several programming languages including C#, C++, Java, Objective-C, Python, Ruby, Go, and Node.js — and the list is growing. Support for gRPC was introduced in .NET Core 3.0, which makes gRPC a first-class citizen in the .NET Core ecosystem.

gRPC provides the following benefits:

  • High performance
  • Light weight
  • Support for bi-directional streaming
  • Support for binary serialization using Protocol Buffers
  • Support for language agnostic implementations

gRPC communication patterns

gRPC supports the following communication patterns.

  • Unary RPC: The client sends a single request and the server sends back a single response.
  • Server streaming RPC: The client sends a single request and the server sends back a stream of responses. 
  • Client streaming RPC: The client sends a stream of messages to the server and the server sends back a single response.
  • Bi-directional streaming RPC: The client sends a stream of messages to the server and the server sends back a stream of responses.

Now let’s get started. To work with the code examples provided in this article, you should have Visual Studio 2019 installed in your system. If you don’t already have a copy, you can .

IDG

Output from our demo gRPC server application (left) and gRPC client (right). 

Two of the biggest benefits of gRPC are its support for bidirectional streaming over HTTP/2 and its binary message format for information exchange. You can take advantage of gRPC to build microservices-based applications, native mobile applications, and Internet of Things (IoT) applications. 

And building a gRPC service is easy. You don’t have to define controllers on the server side (like you do for a RESTful service) or build HTTP requests on the client side to consume the services. We’ll explore working with gRPC in more depth in future posts here.

How to do more in ASP.NET Core:

Copyright © 2020 IDG Communications, Inc.

LEAVE A REPLY