gRPC says Hi to
.NET
Yu-Lang Chu
.NET Developer from APIs to APIs
WCFRest OData
gRPCRest GraphQL
.NET 4.X
.NET 5
gRPC in .NET
● Developed at Google in 2015
● CNCF project
● Official support .NET core 3.0
● Replace WCF in .NET ecosystem
What is gRPC:
General-purpose Remote Procedure Calls
Latest new technologies
C# Service
gRPC Server
JS Client
gRPC Client
stub
Python Client
gRPC Client
stub
HTTP/2
Protobuf
Interoperability
Rest API vs gRPC
● Resource/Content first - JSON
● Human Readable content - JSON
● Text serialization - JSON
● HTTP verbs
● Contract first - protobuf
● Human Readable contract - protobuf
● Binary serialization - protobuf
● No limitation to verbs
https://martin.kleppmann.com/2012/12/05/schema-evolution-in-avro-protocol-buffers-thrift.html
Performance: Protobuf vs XML vs JSON
https://digitallife.rocks/2019/05/30/how-to-save-money-with-technology-protobuf/
Protobuf : core of gRPC
GeneratorProtobuf
C# class
Python class
Golang struct
Message
Protobuf vs WCF
https://docs.microsoft.com/en-us/dotnet/architecture/grpc-for-wcf-developers/migrate-request-reply
Definition of Protobuf
Syntax version
options
package(protobuf)
Service definition
Message
Types of method: WCF vs gRPC
https://docs.microsoft.com/en-us/dotnet/architecture/grpc-for-wcf-developers/rpc-types
4 type of service method
client server
client server
client server
client server
Unary
Client Streaming
Server Streaming
Bidirectional
Streaming
Scenarios
Feature: low latency, high throughput, stream, cross-platform
4 recommended scenarios:
● Microservice
● Point-to-point real time communication
● Multi-language environments
● Network constrained environments
Demo: how to start GRPC project
How to create gRPC server project
● VS2019:
● Command line : dotnet new grpc
● Existing project:
○ add package Grpc.AspNetCore
○ Startup.cs: Add gRPC services and endpoint
How to create gRPC Client project
Project setup:
1. Install Packages:
● Google.Protobuf
● Grpc.Net.Client
● Grpc.Tools
2. Add Protobuf files reference into .csproj, then build project
Code:
3. Setup channel: var channel = Grpc.channel.ForAddress(...);
4. Call defined API
More Topics
● Protobuf definition
● Authentication/Authorization
● Cache
● Rate limiting
● GRPC web
● ….. etc
Reference
● https://developers.google.com/protocol-buffers
● https://docs.microsoft.com/en-us/dotnet/architecture/grpc-for-wcf-developers/
● https://grpc.io/
● https://github.com/grpc/grpc-dotnet

gRPC