如何使用 grpc-web 和使用 protobuf-net 的代码优先 grpc 服务?

问题描述 投票:0回答:1

我们使用codefirst protobuf-net方法开发了grpc服务。我们如何使用 grpc-web 从 javascript 调用这些服务?如果我们没有 .proto 文件,我们如何生成 grpc javascript 客户端代码?

谢谢

grpc protobuf-net grpc-web
1个回答
0
投票

参考 https://protobuf-net.github.io/protobuf-net.Grpc/createProtoFile 将您的 codefirst 文件转换为 protobuf 文件。像这样,使用

protobuf-net.Reflection
包:

var generator = new SchemaGenerator
{
    ProtoSyntax = ProtoSyntax.Proto3
};

var schema = generator.GetSchema<ICalculator>(); // there is also a non-generic overload that takes Type

using (var writer = new System.IO.StreamWriter("services.proto"))
{
    await writer.WriteAsync(schema);
}
© www.soinside.com 2019 - 2024. All rights reserved.