top of page

How To Create gRPC Server in .NET and Add gRPC-Web - C# & .NET

In gRPC world, there is no text-to-binary conversion, so the machines do not spend time to convert data to the format they can read. However, gRPC utilizes HTTP/2 protocol, which is not yet supported with current browsers. That is what gRPC-Web was introduced. gRPC-Web uses HTTP/1.1 protocol in browsers.

In .NET 7, there is a new feature called JSON Transcoding, which uses Google API to convert data to be compatible with current browsers. However, my tests has shown that this feature still requires maturity. If you have .NET gRPC server with gRPC-Web feature built-in, you would not need a separate gRPC-Web Envoy proxy, one less component to worry about. This server can be used with any JavaScript-based or .NET apps.

 

1. Create gRPC Server

The easiest way is to use a boilerplate template in Visual Studio 2022. New Project > Select ASP.NET Core gRPC Service

 

2. Add gRPC-Web Feature

a. Install Grpc.AspNetCore.Web library from Nuget package installer. You can also install it using Package Manager Console by typing the following command:

install-package Grpc.AspNetCore.Web

b. Add new lines of code in Program.cs file. The code below is an example for adding GreeterService to gRPC-Web endpoints.


Also you must delete or at least comment the following line so that there is no endpoint conflict:


You can set a service either gRPC or gRPC-Web, not both.

 

Using this example, GreeterService is now on gRPC-Web endpoint. You can set up gRPC-Web clients on client apps and consume data using this service.

Comentários


pngegg (11)_result.webp

<Raank:랑크 /> 구독 하기 : Subscribe

감사합니다! : Thanks for submitting!

bottom of page