Search code examples
.netasp.net-coregrpcgrpc-web

Calling a .Net framework gRPC service from a web app


I know it's possible to set up a gRPC server and client scenario using only .Net Framework (two console applications for example). It is also possible to setup a web app client (in my case using Angular) and a .Net Core gRPC server app with the Grpc.AspNetCore.Web package.

However, is is possible to call a .Net framework gRPC service from a web app when it won't work with Grpc.AspNetCore.Web?


Solution

  • The complete workflow would be like this:

    1. To your existing protoc you would need to add protoc-gen-grpc-web plugin: download from https://github.com/grpc/grpc-web/releases -- configuration options are here: https://github.com/grpc/grpc-web#client-configuration-options

    2. You would need to start envoy proxy (it's not the only option, but now it seems to be most used and supported), configuration seems to be complicated, but it's just verbose. Good starting point is here: https://github.com/grpc/grpc-web/blob/master/net/grpc/gateway/examples/echo/envoy.yaml

    3. JS frontend just uses generated code, it can be as simple as this: https://github.com/grpc/grpc-web#3-write-your-js-client

    Client is sending gRPC-web requests to Envoy (so you create usual gRPC messages and services in JS and those are translated to HTTP requests), Envoy translates this to regular gRPC call and sends it to your gRPC service. Similar for response.