为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

C#
侃侃尔雅 2023-05-13 15:53:34
我按照以下说明创建了一个 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/grpcinfo: 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;}
查看完整描述

4 回答

?
暮色呼如

TA贡献1853条经验 获得超9个赞

进入 programs.cs 并添加您的服务。



// Configure the HTTP request pipeline.

app.MapGrpcService<GreeterService>(); // here's a service

app.MapGrpcService<UserAuthService>(); // another service i created

app.MapGrpcService<BusinessService>(); // also another service created


app.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();


查看完整回答
反对 回复 2023-05-13
?
明月笑刀无情

TA贡献1828条经验 获得超4个赞

我发现了问题。

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


查看完整回答
反对 回复 2023-05-13
?
森林海

TA贡献2011条经验 获得超2个赞

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



查看完整回答
反对 回复 2023-05-13
?
aluckdog

TA贡献1847条经验 获得超7个赞

只是为这个问题贡献我自己的解决方案,这可能对那些在 C# 中使用代码优先 grpc 的人有用。

我未能完全转换现有的 GRPC 服务项目以采用代码优先 GRPC 支持,特别是我的 program.cs 缺少对以下内容的调用:

builder.Services.AddCodeFirstGrpc();

我的代码中仍然有替代方案,因此删除了以下内容:

builder.Services.AddGrpc();

此外,我之前按照其他回复中的建议检查了我的命名空间混淆代码。我的 grpc 服务接口定义和服务实现是在不同的命名空间中声明的,但是一旦使用 AddCodeFirstGrpc() 正确初始化,这不会导致代码优先 grpc 失败。


查看完整回答
反对 回复 2023-05-13
  • 4 回答
  • 0 关注
  • 179 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信