public IActionResult Index() { var client = new EmployeeService.EmployeeServiceClient(channel); EmployeeList employee = client.GetAll(new Empty()); return(View(employee)); }
public static async Task GetAllAsync(EmployeeService.EmployeeServiceClient client) { try { if (!NeedToken() || await GetTokenAsync(client)) { var headers = new Metadata { { "Authorization", $"Bearer {_token}" } }; using var call = client.GetAll(new GetAllRequest(), headers); var responseStream = call.ResponseStream; while (await responseStream.MoveNext()) { Console.WriteLine(responseStream.Current.Employee); } } } catch (RpcException e) { Log.Logger.Error($"{JsonConvert.SerializeObject(e.Trailers)}"); Log.Logger.Error(e.Message); } }
private static async Task GetAllAsync(EmployeeService.EmployeeServiceClient client) { using var call = client.GetAll(new GetAllRequest()); var responseStream = call.ResponseStream; while (await responseStream.MoveNext()) { Console.WriteLine(responseStream.Current.Employee); } }
public static async Task GetAllAsync(EmployeeService.EmployeeServiceClient client) { using var call = client.GetAll(new GetAllRequest()); var responseSteam = call.ResponseStream; while (await responseSteam.MoveNext()) { Log.Debug($"response message : {responseSteam.Current.Employee}"); Console.WriteLine($"response message : {responseSteam.Current.Employee}"); } }
// server stream static async Task GetAll(EmployeeService.EmployeeServiceClient client) { Console.WriteLine($"GetAll - Server streaming sample"); using (var call = client.GetAll(new GetAllRequest())) { var responserStream = call.ResponseStream; while (await responserStream.MoveNext()) { Console.WriteLine(responserStream.Current.Employee); } } }
public async Task <List <Models.Employee> > GetAllAsync() { var result = new List <Models.Employee>(); using (var call = _employeeServiceClient.GetAll(new ProtocolBuffers.GetAllRequest())) { while (await call.ResponseStream.MoveNext()) { result.Add(_employeeConverter.ToModel(call.ResponseStream.Current.Employee)); } } return(result); }
static async Task GetAllAsync(EmployeeService.EmployeeServiceClient client) { if (!NeedToken() || await CreateTokenAsync(client)) { var header = new Metadata { { "Authorization", $"Bearer {_token}" } }; using var call = client.GetAll(new GetAllRequest(), header); var responseSream = call.ResponseStream; while (await responseSream.MoveNext()) { Console.WriteLine(responseSream.Current.Employee); } } }
public async Task <List <Employee> > GetAll() { //传入元数据 using var channel = GrpcChannel.ForAddress("http://localhost:6001"); var client = new EmployeeService.EmployeeServiceClient(channel); List <Employee> employees = new List <Employee>(); using var call = client.GetAll(new GetAllRequest()); var responseStream = call.ResponseStream; while (await responseStream.MoveNext()) { employees.Add(responseStream.Current.Employee); } return(employees); }
static async Task Main(string[] args) { var metaDatas = new Metadata { { "username", "Leon" }, { "role", "administrator" }, }; using var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new EmployeeService.EmployeeServiceClient(channel); var response = await client.GetByNoAsync(new GetByNoRequest() { No = 102 }, metaDatas); Console.WriteLine(response.Employee.FirstName); using var getAllCall = client.GetAll(new GetAllRequest()); var responseStream = getAllCall.ResponseStream; while (await responseStream.MoveNext()) { Console.WriteLine(responseStream.Current.Employee.FirstName); } FileStream fileStream = File.OpenRead("Dream_x280.jpg"); using var uploadPhotoCall = client.UploadPhoto(); while (fileStream.Position < fileStream.Length) { var buffer = new byte[1024]; int length = await fileStream.ReadAsync(buffer, 0, buffer.Length); if (length < buffer.Length) { Array.Resize(ref buffer, length); } await uploadPhotoCall.RequestStream.WriteAsync( new UploadPhotoRequest() { Data = ByteString.CopyFrom(buffer) }); } await uploadPhotoCall.RequestStream.CompleteAsync(); using var saveAllCall = client.SaveAll(); for (int index = 0; index < 5; index++) { await saveAllCall.RequestStream.WriteAsync(new EmployeeRequest() { Employee = new Employee() { Id = 10 + index, FirstName = "Employee", LastName = index.ToString(), No = 110 + index, Salary = 10000 + index * 1000, } }); } await saveAllCall.RequestStream.CompleteAsync(); while (await saveAllCall.ResponseStream.MoveNext()) { Console.WriteLine(saveAllCall.ResponseStream.Current.Employee.Id); } Console.ReadLine(); }