SHARE:

gRPC & ASP.NET Core 5: Add a gRPC service reference from a remote protobuf over Route-To-Code

Introduction

A while ago, I published a post that explained how to expose proto files within an ASP.NET Core gRPC app using Route-To-Code that you can find here: Exposing proto files in a gRPC service over a frameworkless and lightweight API – Anthony Giretti’s .NET blog

I only explained how to expose them and access them from a browser. But I haven’t explained how to download them from “Services References” menu in Visual Studio 2019, and I should have because there is a trick.

gRPC works only with HTTP/2

And that’s the trick! Kestrel in a gRPC service template, will ONLY expose endpoints on HTTP/2 because gRPC works only on HTTP/2. If you take the following endpoint that I use to expose a proto file: https://localhost:5001/protos/v2/country.proto it will work in a browser but not in Visual Studio 2019. Example:

Visual Studio 2019 uses only HTTP/1 on Service configuration process. To demonstrate it, here is the error encountered the server side:

To fix that, you just have to go to the ASP.NET Core gRPC app and edit the appsettings file then enable HTTP/1 and HTTP/2 like this:

{
   "AllowedHosts": "*",
   "Kestrel": {
   "EndpointDefaults": {
      "Protocols": "Http1AndHttp2"
      }
   }
}

Now if you go back to Visual Studio 2019 you should be able to download the proto file:

Hope this article helped you 😉

Written by

anthonygiretti

Anthony is a specialist in Web technologies (14 years of experience), in particular Microsoft .NET and learns the Cloud Azure platform. He has received twice the Microsoft MVP award and he is also certified Microsoft MCSD and Azure Fundamentals.
%d bloggers like this: