Proxy GRPC C# services

628 views
Skip to first unread message

Aggarwal Sre

unread,
Apr 9, 2021, 8:10:26 PM4/9/21
to grpc.io

Hi GRPC Team,

 

Is there a recommended pattern for implementing transparent proxy for ASP.NET GRPC services?  For golang I found some implementation based of – “grpc.UnknownServiceHandler” - grpc · pkg.go.dev


Basically, I am trying to see if there is a way to do something like following in C#, which gives access to streams

 

grpc-proxy/handler.go at master · mwitkow/grpc-proxy · GitHub

 

fakeDesc := &grpc.ServiceDesc{

ServiceName: serviceName,

HandlerType: (*interface{})(nil),

       }

 

Regards,

Vivek Aggarwal

Jan Tattermusch

unread,
Apr 26, 2021, 3:49:53 AM4/26/21
to grpc.io
Hello,

I don't know of a ready-to-use generic proxy for ASP.NET, but it's something that wouldn't be hard to implement.  Important things to know:
1. instead of de-serializing the message payload, one would need to use a custom serializer/deserializer that would simply read the payloads as binary blobs (as in the general case you don't know the type of the message in a generic rpc).
2. you would only need to have one generic bi-di streaming handler for all types of RPCs. In a sense, the unary / client streaming / server streaming calls are just a special case of a bi-di streaming call. The information which RPC is unary (or other kind) basically only comes from the .proto schema and it doesn't change how the RPCs looks on the wire.
3. an unknown service handler is also implemented in grpc-dotnet - you can take a look at the source code and perhaps that would give you some tips on how to implement a "fallback" handler.
4. in ASP.NET core, since it's a HTTP/2 server, you could simply implement the proxy a HTTP/2 request forwarder (each RPC will be a new HTTP/2 stream and will invoke a separate HTTP/2 request handler).

So I believe a basic generic proxy that forwards all RPCs could be written in <100 lines code. Besides that, since gRPC works over HTTP/2, any HTTP/2 compliant proxy would also work for proxying gRPC traffic.
Reply all
Reply to author
Forward
0 new messages