static async Task Main(string[] args) { const string host = "localhost"; const int port = 50051; const string stopMessage = "stop"; var channel = new Channel($"{host}:{port}", ChannelCredentials.Insecure); var client = new CalculatorService.CalculatorServiceClient(channel); Console.WriteLine("Client sending request: "); using (var call = client.Calculate()) { var responseReaderTask = Task.Run(async() => { while (await call.ResponseStream.MoveNext()) { var response = call.ResponseStream.Current; Console.WriteLine("Received: " + response); } }); string input = Console.ReadLine(); while (input != stopMessage) { try { if (double.TryParse(input, out double operand)) { await call.RequestStream.WriteAsync(new OperationRequest() { Operand = new Operand() { Value = operand } }); } else if (Enum.TryParse(input, out OperationType operation)) { await call.RequestStream.WriteAsync(new OperationRequest() { Operation = operation }); } } catch (Exception exception) { Console.WriteLine(exception.Message); } input = Console.ReadLine(); } await call.RequestStream.CompleteAsync(); await responseReaderTask; } }
protected void btnDivide_Click(object sender, EventArgs e) { int numerator = Convert.ToInt32(txtNumerator.Text); int denominator = Convert.ToInt32(txtDenominator.Text); CalculatorService.CalculatorServiceClient client = new CalculatorService.CalculatorServiceClient(); lblResult.Text = client.Divide(numerator, denominator).ToString(); }
protected void btnDivide_Click(object sender, EventArgs e) { CalculatorClient.CalculatorService.CalculatorServiceClient client = new CalculatorService.CalculatorServiceClient(); try { lblMessage.Text = client.Divide(Convert.ToInt32(txtNumerator.Text), Convert.ToInt32(txtDenomirator.Text)).ToString(); } catch (FaultException faultException) { lblMessage.Text = faultException.Message; //Log exception } }
protected void btnDivide_Click(object sender, EventArgs e) { try { int numerator = Convert.ToInt32(txtNumerator.Text); int denominator = Convert.ToInt32(txtDenominator.Text); CalculatorService.CalculatorServiceClient client = new CalculatorService.CalculatorServiceClient(); lblResult.Text = client.Divide(numerator, denominator).ToString(); } catch (FaultException faultexception) { lblResult.Text = faultexception.Message; } }
static void Main(string[] args) { // Create the new proxy proxy = new CalculatorService.CalculatorServiceClient(); // Store persons name name = AskServiceName(); // Continuously ask for what service to do while (true) { // Ask what the user wants to do AskUserText(); var input = Console.ReadLine(); // Exit loop if (input.Equals("0")) { break; } // Else check values switch (input) { case "1": AdditionService(); break; case "2": SubtractService(); break; case "3": DivideService(); break; case "4": GetRequestService(); break; } } }
protected void btnDivide_Click(object sender, EventArgs e) { CalculatorClient.CalculatorService.CalculatorServiceClient client = new CalculatorService.CalculatorServiceClient(); lblMessage.Text = client.Divide(Convert.ToInt32(txtNumerator.Text), Convert.ToInt32(txtDenomirator.Text)).ToString(); }
public MainWindow() { InitializeComponent(); client = new CalculatorService.CalculatorServiceClient(); }