我正在将预告片从服务器发送到客户端,但在客户端我无法访问这些预告片。
服务器:
// UserContract.cs
public Task<User> GetUserAsync(UserDto userDto, CallContext context = default)
{
try
{
throw new NotImplementedException();
}
catch
{
Metadata metadata = new Metadata { { "test", "testvalue" } };
throw new RpcException(new Status(StatusCode.Internal, "Error"), metadata);
}
}
客户端(Blazor):
try
{
await this.FactoryGrpc.CreateService<IUserContract>().GetUserAsync(userDto);
}
catch (RpcException exp)
{
if (exp.Trailers.Count == 0)
{
this.Popup.ShowMessage("Where's the trailer?");
return;
}
this.Popup.ShowMessage(exp.Trailers.GetValue("test"));
}
它正在进入if。拖车计数应为 1 时为 0。