blazor wasm——托管+;gRCP网络(流)

blazor wasm——托管+;gRCP网络(流),blazor,blazor-client-side,grpc-web,Blazor,Blazor Client Side,Grpc Web,是否可以通过gRCP web(http/1.1)执行cleint服务器流式响应 我有一个工作的客户机/服务器+db解决方案,但似乎我必须等待完整的服务器响应(请参阅服务器中的//wait Task.Delay(2000);) 我希望发生的是,客户机应该在它发送回客户机的每个“服务器勾号”上进行渲染,而不是等待流关闭并呈现完整响应 有IDE吗 Proto syntax=“proto3”; 选项csharp_namespace=“GrpcReports”; 一揽子报告; 服务报告{ rpc AllR

是否可以通过gRCP web(http/1.1)执行cleint服务器流式响应

我有一个工作的客户机/服务器+db解决方案,但似乎我必须等待完整的服务器响应(请参阅服务器中的
//wait Task.Delay(2000);

我希望发生的是,客户机应该在它发送回客户机的每个“服务器勾号”上进行渲染,而不是等待流关闭并呈现完整响应

有IDE吗

Proto

syntax=“proto3”;
选项csharp_namespace=“GrpcReports”;
一揽子报告;
服务报告{
rpc AllReports(ReportRequest)返回(stream ReportReply);
}
消息报告请求{}
消息报告回复{
字符串名称=1;
}
服务器

//服务器
公共类ReportsService:Reports.ReportsBase
{
专用只读IReportRepository\u存储库;
专用只读IMapper\u映射器;
公共报表服务(IReportRepository存储库,IMapper映射器)
{
_repository=repository??抛出新ArgumentNullException(nameof(IReportRepository));
_mapper=mapper??抛出新的ArgumentNullException(nameof(IMapper));
}
公共重写异步任务AllReports(ReportRequest请求、IServerStreamWriter响应流、ServerCallContext上下文)
{
foreach(在_mapper.Map(wait _repository.GetAllReportsAsync())中的var项)
{
日志信息(“{@ReportReply}”,项目);
等待响应eam.WriteAsync(项目);
//等待任务。延迟(2000);
}
}
}
客户端

@page/“
@使用Grpc.Core
@使用GrpcReports
@使用自动映射器
@注入报告。报告客户端\u报告客户端
@注入IMapper\u映射器
调用gRPC服务
呼叫gRPC服务
来自数据库的服务器报告响应:

    @foreach(reportReplys中的var项) {
  • @项目名称
  • }
@代码{ List reportReplys=新列表(); 异步任务AllReports() { 使用(var call=\u reportsClient.AllReports(new ReportRequest())) { while(等待call.ResponseStream.MoveNext()) { reportReplys.Add(调用?.ResponseStream?.Current); } } } }

所以gRPC web流确实有效,我唯一需要添加的就是在每个服务器上重新呈现UI

唯一需要添加到代码中的是
statehaschange()

客户端端更新:

while(等待调用?.ResponseStream?.MoveNext())
{
reportReplys.Add(调用?.ResponseStream?.Current);
StateHasChanged();
}
参考: