Reputation: 2411
I am currently trying to implement a gRPC server in an existing C# ASP .NET Core application. But the C# bindings aren't being generated to use within the application. I have installed the following dependencies:
I have added the .proto
file to the Protos
folder in my project. I have the following .proto
configuration:
syntax = "proto3";
//Request that comes through from the microservice endpoint
message RegistrationRequest {
string type = 1;
string ipAddress = 2;
}
//Response on the service register endpoint
message RegistrationResponse {
bool accepted = 1;
}
//Request to get API endpoint to use based on type
message HostRequest {
string type = 1;
}
//Response of the host request
message HostResponse {
string ipAddress = 1;
}
//Service for the repository
service ServiceRepoServer {
//Method that will register the endpoint on the repo
rpc RegisterEndpoint (RegistrationRequest) returns (RegistrationResponse) {}
//Method that will return an endpoint based on type
rpc RequestEndpoint (HostRequest) returns (HostResponse) {}
}
I have tried cleaning and rebuilding to no avail. It is probably somethind small I am missing somewhere but I am not sure what it is. Does someone have an idea?
Upvotes: 5
Views: 6865
Reputation: 876
You need to edit csproj, for example the default greet.proto does this:
<ItemGroup>
<Protobuf Include="Protos\greet.proto" GrpcServices="Server" />
</ItemGroup>
GrpcServices
parameter can also be Client
or Both
depends on what you need.
If you're using Visual Studio 2019, you can also use build action to do this. Right click on your proto file and select properties. Choose Protobuf compiler
in Build Action
Upvotes: 11