I want to use gRPC with .NET in an asp.net core web application. How do I generate the necessary .proto file from an existing C# class and model objects? I don't want to re-write a .proto file that mirrors the existing code, I want the .proto file to be auto-generated from the class and model objects.
I call this method to register my service class.
builder.MapGrpcService<MyGrpcService>();
public class MyGrpcService
{
public Task<string> ServiceMethod(ModelObject model, ServerCallContext context)
{
return Task.FromResult("It Worked");
}
}
ModelObject
has [DataContract]
and [DataMember]
with order attributes.
Is this possible? Every example I see online starts with a .proto
file. I've already defined my desired service methods in the MyGrpcService
class. But maybe this is just backwards to what is the standard way of doing things...
Something like the old .NET remoting would be ideal where you can just ask for an interface from a remote end point and it magically uses gRPC
to communicate back and forth, but maybe that is too simplistic a view.