// Evaluates two numbers and an operator server side private double EvaluateOperator(string cmd, double n1, double n2) { double result = 0; switch (cmd) { case "+": result = client.Add(n1, n2); break; case "-": result = client.Subtract(n1, n2); break; case "*": result = client.Multiply(n1, n2); break; case "/": result = client.Divide(n1, n2); break; case "%": result = client.Modulo(n1, n2); break; case "^": result = client.Power(n1, n2); break; } return(result); }
static void RunProxy01(string endpointAddress, int x, int y) { Console.WriteLine("Run Proxy01 {"); var client = new CalculatorClient(new BasicHttpBinding(), new EndpointAddress(endpointAddress)); Console.WriteLine($" {x} + {y} == {client.Add(x, y)}"); Console.WriteLine($" {x} - {y} == {client.Subtract(x, y)}"); Console.WriteLine($" {x} * {y} == {client.Multiply(x, y)}"); Console.WriteLine($" {x} / {y} == {client.Divide(x, y)}"); Console.WriteLine("}"); }
static void Main(string[] args) { //Step 1: Create an endpoint address and an instance of the WCF Client. CalculatorClient client = new CalculatorClient(); // Step 2: Call the service operations. // Call the Add service operation. double value1 = 100.00D; double value2 = 15.99D; double result = client.Add(value1, value2); Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result); // Call the Subtract service operation. value1 = 145.00D; value2 = 76.54D; result = client.Subtract(value1, value2); Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result); // Call the Multiply service operation. value1 = 9.00D; value2 = 81.25D; result = client.Multiply(value1, value2); Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result); // Call the Divide service operation. value1 = 22.00D; value2 = 7.00D; result = client.Divide(value1, value2); Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result); //Step 3: Closing the client gracefully closes the connection and cleans up resources. client.Close(); Console.WriteLine(); Console.WriteLine("Press <ENTER> to terminate client."); Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("Client Connecting..."); CalculatorClient client = new CalculatorClient(); client.Open(); Console.Write("Adding 2 + 2 - Answer: "); Console.WriteLine(client.Add(2, 2)); Console.Write("Subtracting 2 - 2 - Answer: "); Console.WriteLine(client.Subtract(2, 2)); Console.Write("Dividing 2 / 2 - Answer: "); Console.WriteLine(client.Divide(2, 2)); Console.Write("Multiplying 2 * 2 - Answer: "); Console.WriteLine(client.Multiply(2, 2)); client.Close(); Console.ReadLine(); }
static void Main(string[] args) { Action <string> PrintTitle = (title) => { Console.WriteLine(); Console.WriteLine(new String('=', 70)); Console.WriteLine(title); Console.WriteLine(new String('=', 70)); }; CalculatorClient client = new CalculatorClient(); PrintTitle("Adding Example"); var result = client.Add(50, 50); Console.WriteLine($"50 + 50 = {result}"); PrintTitle("Subtraction Example"); var subresult = client.Subtract(500, 50); Console.WriteLine($"500 - 50 = {subresult}"); PrintTitle("Multiplication Example"); var mulresult = client.Multiply(25, 25); Console.WriteLine($"25 * 25 = {mulresult}"); PrintTitle("Division Example"); var divresult = client.Divide(500, 50); Console.WriteLine($"500 / 50 = {divresult}"); client.Close(); }