.net - 使用自动生成时如何在 .proto 文件中包含服务 (Serializer.GetProto<>())
问题描述
因此,我需要创建一个包含服务和消息的完整 .proto 文件,以完整描述我将要使用的服务之一。我已经发现这篇文章提到了使用
string proto = Serializer.GetProto<YourType>();
但遗憾的是,当在我的服务上使用它时,它只会生成一个带有以我的服务命名的“消息”的原始文件。
谈谈我在下面给出的具体文件示例,有没有办法从 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 票,但需要一些时间。现在,您可能需要手动破解它。
推荐阅读
- javascript - 使用按钮隐藏和显示 div
- python-3.x - 基于 Python Polars 列的更新不起作用
- python - Python规避无法访问自我
- marklogic - 什么是/为什么是 Marklogic Grove?
- java - 仅针对一种方法更改 Hibernate 事务超时?
- python - 创建具有不同元素大小python的数组或列表
- gtk - 使用 Gtk::SpinButton::set_value() - 信号/插槽时卡住
- c++ - 两个值分别大于 x 和 y 的对数
- visual-studio - 无法在 Visual Studio 中构建 docker-compose 项目
- c# - 'Xamarin.Forms.Build.Tasks, Version = 0.0.0.0 , Culture = 中性, PublicKeyToken = null '或其依赖项之一