Ste*_*ini 5 c# grpc asp.net-core
我在这条指令之后创建了一个 grpc 服务器和客户端:https ://docs.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
Run Code Online (Sandbox Code Playgroud)
原型文件:
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
Run Code Online (Sandbox Code Playgroud)
服务器启动:
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;
}
message Events{
repeated Event events = 1;
}
message Locations{
repeated Location locations = 1;
}
message Participants{
repeated Participant participants = 1;
}
message Event {
Id eventid = 1;
string name = 2;
string description = 3;
Id locationID = 4;
string date = 5;
}
message Location {
Id locationID = 1;
string name = 2;
string adress = 3;
}
message Participant {
Id participantId = 1;
string name = 2;
Id eventId = 3;
}
Run Code Online (Sandbox Code Playgroud)
定位服务:
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
var connectionString = @"Data Source=STEINI-PC;Initial Catalog=thesisSteinmetz;Persist Security Info=True;User ID=SA;Password=SA123";
services.AddGrpc(options =>
{
options.EnableDetailedErrors = true;
});
services.AddDbContext<DataContext>(options => options.UseSqlServer(connectionString));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
// 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
endpoints.MapGrpcService<EventService>();
endpoints.MapGrpcService<LocationService>();
endpoints.MapGrpcService<ParticipantService>();
});
}
}
Run Code Online (Sandbox Code Playgroud)
小智 11
进入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();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7469 次 |
| 最近记录: |