1
votes

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.

1
StackOverflow is not a code generation site. What have you tried so far?Danny Goodall
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: protobuf-net.github.io/protobuf-net.Grpc/gettingstartedMarc Gravell

1 Answers

2
votes

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.