grpc 服务器显示“未实现的服务错误”

我按照以下说明创建了一个 grpc 服务器和客户端:https://learn.microsoft.com/en-us/aspnet/core/tutorials/grpc/grpc-start ?view=aspnetcore-3.0&tabs=visual-studio 。

当我尝试从客户端调用服务时,客户端显示此错误消息:“发生一个或多个错误。(Status(StatusCode=Unknown, Detail="No status received"))"

和服务器这个:

info: Microsoft.AspNetCore.Hosting.Diagnostics[1]

      Request starting HTTP/2 POST http://STEINI-PC/LocationService/GetLocations application/grpc

info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]

      Executing endpoint 'gRPC - gRPC - Unimplemented service'

info: Grpc.AspNetCore.Server.Internal.ServerCallHandlerFactory[1]

      Service 'LocationService' is unimplemented.

info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]

      Executed endpoint 'gRPC - gRPC - Unimplemented service'

info: Microsoft.AspNetCore.Hosting.Diagnostics[2]

      Request finished in 51.812000000000005ms 200 application/grpc

原型文件:


syntax = "proto3";


service EventService {

    rpc GetEvents (Empty) returns (Events) {}

    rpc GetEvent (Id) returns (Event) {}

    rpc GetEventsByLocation (Id) returns (Events) {}

    rpc AddEvent (Event) returns (Empty) {}

    rpc UpdateEvent (Event) returns (Empty) {}

    rpc DeleteEvent (Id) returns (Event) {}

}


service LocationService {

    rpc GetLocations (Empty) returns (Locations) {}

    rpc GetLocation (Id) returns (Location) {}

    rpc AddLocation (Location) returns (Empty) {}

    rpc UpdateLocation (Location) returns (Empty) {}

    rpc DeleteLocation (Id) returns (Location) {}

}


service ParticipantService {

    rpc GetParticipants (Empty) returns (Participants) {}

    rpc GetParticipant (Id) returns (Participant) {}

    rpc GetParticipantsFromEvent (Id) returns (Participants) {}

    rpc AddParticipant (Participant) returns (Empty) {}

    rpc UpdateParticipant (Participant) returns (Empty) {}

    rpc DeleteParticipant (Id) returns (Participant) {}

}


message Empty {


}


message Id {

    string id = 1;

}


侃侃尔雅
浏览 185回答 4
4回答

暮色呼如

进入 programs.cs 并添加您的服务。// Configure the HTTP request pipeline.app.MapGrpcService<GreeterService>(); // here's a serviceapp.MapGrpcService<UserAuthService>(); // another service i createdapp.MapGrpcService<BusinessService>(); // also another service createdapp.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");app.Run();

明月笑刀无情

我发现了问题。我的问题是生成文件的不同命名空间,我手动编辑了这些文件。

森林海

如果您在原型中使用“包”,请确保服务器端与客户端匹配。

aluckdog

只是为这个问题贡献我自己的解决方案,这可能对那些在 C# 中使用代码优先 grpc 的人有用。我未能完全转换现有的 GRPC 服务项目以采用代码优先 GRPC 支持,特别是我的 program.cs 缺少对以下内容的调用:builder.Services.AddCodeFirstGrpc();我的代码中仍然有替代方案,因此删除了以下内容:builder.Services.AddGrpc();此外,我之前按照其他回复中的建议检查了我的命名空间混淆代码。我的 grpc 服务接口定义和服务实现是在不同的命名空间中声明的,但是一旦使用 AddCodeFirstGrpc() 正确初始化,这不会导致代码优先 grpc 失败。
打开App,查看更多内容
随时随地看视频慕课网APP