1

So I need to create a full .proto file with a service and messages to fully describe one of the services I'm going to use. I already found this post that mentions the use of string proto = Serializer.GetProto<YourType>(); But sadly when used on my service it just generates a proto file with a "message" named after my service.

Talking with a the concrete file examples I give bellow, is there a way to get the Example.proto from the IExampleService.cs?

[ServiceContract]
public interface IExampleService
{
    Task<ExampleReply> ExampleMethod(ExampleRequest request);
}

[ProtoContract]
public class ExampleRequest
{
    [ProtoMember(1)]
    public string Prop1 { get; set; }

    [ProtoMember(2, DataFormat = DataFormat.WellKnown)]
    public DateTime TimeProp2 { get; set; }
}

[ProtoContract]
public class ExampleReply
{
    [ProtoMember(1)]
    public string Prop1 { get; set; }
}

Example.proto file

service IExampleService {
    rpc ExampleMethod (ExampleRequest) returns (ExampleReply) {}
}

message ExampleRequest{
   string Prop1 = 1;
   .google.protobuf.Timestamp TimeProp2 = 2;
 }

message ExampleReply {
  string message = 1;
}

1 Answers1

2

Update: this now exists, but it is in protobuf-net.Grpc.Reflection, via the SchemaGenerator type. It also requires protobuf-net v3.


Right now the code to do this has not been written. There is an open github ticket for it, but it will take some time. For now, you'll probably need to hack it by hand.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • Is there any update for this case? Would you like to link the github ticket? I did find this issue: https://github.com/protobuf-net/protobuf-net/issues/687 but it this is to recent, to be the one you are talking about. At least in that case, it looks like this is working already also with services? – DominikAmon Aug 03 '20 at 04:54
  • 1
    @DominikAmon good news, this now exists. Will edit. – Marc Gravell Aug 03 '20 at 07:25