使用自动生成时如何在 .proto 文件中包含服务 (Serializer.GetProto<>())
How to include services in .proto file when using auto-generation (Serializer.GetProto<>())
所以我需要创建一个完整的 .proto 文件,其中包含一项服务和消息,以完整描述我将要使用的其中一项服务。我已经发现 this post 提到了使用
string proto = Serializer.GetProto<YourType>();
但遗憾的是,当在我的服务上使用时,它只会生成一个带有以我的服务命名的 "message" 的原型文件。
与我在下面给出的具体文件示例进行讨论,有没有办法从 IExampleService.cs 中获取 Example.proto?
[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 文件
service IExampleService {
rpc ExampleMethod (ExampleRequest) returns (ExampleReply) {}
}
message ExampleRequest{
string Prop1 = 1;
.google.protobuf.Timestamp TimeProp2 = 2;
}
message ExampleReply {
string message = 1;
}
更新:现在存在,但它在 protobuf-net.Grpc.Reflection 中,通过 SchemaGenerator
类型。它还需要 protobuf-net v3.
目前尚未编写执行此操作的代码。有一个开放的 github 票,但需要一些时间。现在,您可能需要手动破解它。
所以我需要创建一个完整的 .proto 文件,其中包含一项服务和消息,以完整描述我将要使用的其中一项服务。我已经发现 this post 提到了使用
string proto = Serializer.GetProto<YourType>();
但遗憾的是,当在我的服务上使用时,它只会生成一个带有以我的服务命名的 "message" 的原型文件。
与我在下面给出的具体文件示例进行讨论,有没有办法从 IExampleService.cs 中获取 Example.proto?
[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 文件
service IExampleService {
rpc ExampleMethod (ExampleRequest) returns (ExampleReply) {}
}
message ExampleRequest{
string Prop1 = 1;
.google.protobuf.Timestamp TimeProp2 = 2;
}
message ExampleReply {
string message = 1;
}
更新:现在存在,但它在 protobuf-net.Grpc.Reflection 中,通过 SchemaGenerator
类型。它还需要 protobuf-net v3.
目前尚未编写执行此操作的代码。有一个开放的 github 票,但需要一些时间。现在,您可能需要手动破解它。