【发布时间】:2020-05-15 00:59:50
【问题描述】:
所以我需要创建一个包含服务和消息的完整 .proto 文件,以完整描述我将要使用的服务之一。我已经找到this post 提到使用
string proto = Serializer.GetProto<YourType>();
但遗憾的是,在我的服务上使用时,它只会生成一个带有以我的服务命名的“消息”的 proto 文件。
谈谈我下面给出的具体文件示例,有没有办法从 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;
}
【问题讨论】:
标签: .net serialization protocol-buffers grpc protobuf-net