1

I need to write a framework and there are two app which are communicating using gRPC. They share some common proto payload. Now, challenge is this, I want to write some interface and implementation in that proto3 proto contract.It is c# based app so both will generate c# based proto type from .proto file.

Is there any way to achieve the same.

Yogesh
  • 3,044
  • 8
  • 33
  • 60
  • StackOverflow is not a code generation site. What have you tried so far? – Danny Goodall Feb 18 '20 at 08:44
  • As a side note: if both sides are C#, have you considered *not bothering* with a .proto? protobuf-net / protobuf-net.Grpc allow you to work code-first, i.e. you *just* write your DTOs and interfaces in C#, and the library makes it all work; start here: https://protobuf-net.github.io/protobuf-net.Grpc/gettingstarted – Marc Gravell Feb 18 '20 at 08:57

1 Answers1

2

In raw gRPC / .proto terms, this is service:

service MyService {
  rpc SomeMethod (SomeDtoDefinedSomewhere) returns (AnotherDtoDefinedSomewhere);
  rpc AnotherMethod (Blah) returns (Whatever);
}

Now; what happens next depends on the tools you're using; protoc will generate a client proxy and server stub for this, not a C# interface. You can either work with this "as is", or add your own interface as an abstraction.

However, protobuf-net (a separate implementation of protobuf on .NET) can work with this as a pure C# interface via protogen. Unfortunately, I have not yet updated the website with the tweaks to actually emit service definitions as interfaces. But it should work from the nuget preview drops.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900