CRUD using gRPC, EF Core, and ASP.NET Core (Part - 4)
In Part -1,
Part - 2, and
Part -3 of this
article you learned to create and consume the EmployeeCRUD service in ASP.NET
Core. This concluding part of this series discusses some limitations that you
should be aware of while deploying gRPC services with real-world applications.
If you read the official documentation of gRPC available
you will find the following:
This means you cannot host a gRPC service under:
Why so? Basically Azure App Service also uses IIS for hosting the apps. gRPC uses HTTP/2 protocol. More specifically it uses what is known as
response trailing headers. Http.Sys is part of the IIS kernel and as of this
writing it doesn't support response trailing headers required for gRPC
So, what are the options for hosting a gRPC service?
The easiest way is to host a gRPC service in ASP.NET Core's built-in web
server - Kestrel. In fact when you create a new gRPC project in Visual Studio it
uses Kestrel to run the application.
As you can see, by default the gRPC service is made available at
https://localhosy:5001. Note that this URL uses HTTPS and a self-signed
certificate is used. You might want to change the port number at which the gRPC
service is made available. You can do that in two ways.
You can change the port by adding Kestrel section to appsetttings.json file.
In fact if you open appsettings.json you will find this already added for you:
You can modify this section to customize the URL at which the gRPC service is
As you can see, Endpoint section has been added to specify a new end point
URL for publishing the gRPC service. If you run the application now, you will
The URL now reflects the changed port number (12345).
You should now use this new URL in the client code to establish the
var channel = GrpcChannel.ForAddress("https://localhost:12345");
You can also change the end point URL using code as shown below:
public static IHostBuilder CreateHostBuilder
(string args) =>
This code from Program.cs uses the UseUrls() method to change the end point
You might be looking to host your gRPC service in a cloud environment. If so you
can use Azure Kubernetes Service (AKS) to host your gRPC services. You can read
more about AKS
As of this writing there is no specific timeline as to when IIS and Azure App
Service will support gRPC. It seems that this will call for kernel level changes
in IIS and you can read some discussion around this topic
That's it for now! Keep coding!!