Example #1
0
        static void Main(string[] args)
        {
            //Step 1: Create an instance of the WCF proxy.
            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);
            Console.ReadLine();
            //Step 3: Closing the client gracefully closes the connection and cleans up resources.
            client.Close();
        }
Example #2
0
        static void Main(string[] args)
        {
            CalculatorClient client = new CalculatorClient();

            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            value1 = 145D;
            value2 = 76.52D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            value1 = 9D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            value1 = 22D;
            value2 = 7D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            Console.ReadLine();
            client.Close();
        }
Example #3
0
        static void Main(string[] args)
        {
            //Step 1: Create an instance of the WCF proxy.
            CalculatorClient client = new CalculatorClient();

            // Step 2: Call the service operations.
            // Call the Add service operation.
            string fruit  = "apple";
            int    count  = 10;
            int    result = client.Add(fruit, count);

            Console.WriteLine("Adding {0} {1} to the fridge. There is {2} {1} in the fridge", count, fruit, result);

            // Call the Subtract service operation.
            fruit  = "apple";
            count  = 2;
            result = client.Subtract(fruit, count);
            Console.WriteLine("Taking {0} {1} from the fridge. There are {2} {1} left in the fridge", count, fruit, result);

            // Call the Multiply service operation.
            fruit  = "apple";
            result = client.Get(fruit);
            Console.WriteLine("There is {1} {0} in the fridge", fruit, result);

            // Step 3: Close the client to gracefully close the connection and clean up resources.
            Console.WriteLine("\nPress <Enter> to terminate the client.");
            Console.ReadLine();
            client.Close();
        }
Example #4
0
        static void Main(string[] args)
        {
            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);

            Console.ReadKey();

            client.Close();
        }
Example #5
0
        private void btnSubtract_Click(object sender, EventArgs e)
        {
            double val1, val2;

            GetValues(out val1, out val2);
            MessageBox.Show(_client.Subtract(val1, val2).ToString());
        }
Example #6
0
        private static void Calculation(int operation, double arg1, double arg2)
        {
            var calculatorClient = new CalculatorClient();

            switch (operation)
            {
            case 1:
                var result = calculatorClient.Add(arg1, arg2);
                Console.WriteLine($"\nAdd: { arg1 } + { arg2 } = { result }");
                break;

            case 2:
                result = calculatorClient.Subtract(arg1, arg2);
                Console.WriteLine($"\nSubtract: { arg1 } - { arg2 } = { result }");
                break;

            case 3:
                result = calculatorClient.Multiply(arg1, arg2);
                Console.WriteLine($"\nMultiply: { arg1 } * { arg2 } = { result }");
                break;

            case 4:
                result = calculatorClient.Divide(arg1, arg2);
                Console.WriteLine($"\nDivide: { arg1 } / { arg2 } = { result }");
                break;
            }

            calculatorClient.Close();
        }
Example #7
0
        static void Main(string[] args)
        {
            //Step 1: Create an instance of the WCF proxy.
            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: Close the client to gracefully close the connection and clean up resources.
            //Console.WriteLine("\nPress <Enter> to terminate the client.");
            //Console.ReadLine();

            Console.WriteLine("\nEnter a integer to add.");
            double int1 = Convert.ToDouble(Console.ReadLine());

            Console.WriteLine("\nEnter a integer to add.");
            double int2    = Convert.ToDouble(Console.ReadLine());
            var    result1 = client.Multiply(int1, int2);


            Console.WriteLine($"Got the Clients feedback - Multiply({int1},{int2}) = {result1}");


            client.Close();
        }
Example #8
0
        static void Main(string[] args)
        {
            CalculatorClient client = new CalculatorClient();

            double value1 = 100.00d;
            double value2 = 15.99d;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            value1 = 145.00d;
            value2 = 76.54d;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            value1 = 9.00d;
            value2 = 81.25d;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            value1 = 22.00d;
            value2 = 7.00d;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            try
            {
                value1 = 22.0d;
                value2 = 0d;
                result = client.Divide(value1, value2);
                Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
            }
            catch (FaultException <MathFault> ex)
            {
                Console.WriteLine(ex.Detail.ToString());
                client.Abort();
            }

            client.Close();

            Console.ReadLine();
        }
Example #9
0
        static void Main(string[] args)
        {
            //Step 1: Create an instance of the WCF proxy.
            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);

            string str = "HeLLO";
            string res = client.StringOp(str);
            Console.WriteLine("Output is" + res);

            // Step 3: Close the client to gracefully close the connection and clean up resources.
            Console.WriteLine("\nPress <Enter> to terminate the client.");
            Console.ReadLine();
            client.Close();
        }
Example #10
0
        static void Main(string[] args)
        {
            //1: create an instance of the WCF proxy
            CalculatorClient client = new CalculatorClient();

            // 2: Call the service operations;
            //Add service call:
            double val1 = 100.00D;
            double val2 = 15.99D;
            double res  = client.Add(val1, val2);

            Console.WriteLine("Add ({0},{1})={2}", val1, val2, res);

            //Subtract service call:
            val1 = 145.00D;
            val2 = 76.54D;
            res  = client.Subtract(val1, val2);
            Console.WriteLine("Subtract ({0},{1})={2}", val1, val2, res);

            //Multiply service call:
            val1 = 9.00D;
            val2 = 81.25D;
            res  = client.Multiply(val1, val2);
            Console.WriteLine("Multiply ({0},{1})={2}", val1, val2, res);

            //Divide service call:
            val1 = 22.00D;
            val2 = 7.54D;
            res  = client.Divide(val1, val2);
            Console.WriteLine("Divide ({0},{1})={2}", val1, val2, res);

            //3: close client and connection to free resources
            Console.WriteLine("\nPress <Enter> to terminate the client.");
            Console.ReadLine();
            client.Close();
        }
Example #11
0
        static void Main(string[] args)
        {
            //Step 1: Create an instance of the WCF proxy.
            CalculatorClient client    = new CalculatorClient();
            PalindromeClient palClient = new PalindromeClient();


            Console.WriteLine("Simple Calculator");
            Console.WriteLine("Please enter the number for the mathematical:");
            Console.WriteLine("While entering numbers please type the first number and then use enter to type the next number");
            int menuchoice = 0;

            while (menuchoice != 7)
            {
                //Console.WriteLine("Simple Calculator");
                //Console.WriteLine("Please enter the number for the mathematical:");
                //Console.WriteLine("While entering numbers please type the first number and then use enter to type the next number");
                Console.WriteLine();
                Console.WriteLine("1. Add");
                Console.WriteLine("2. Subtract");
                Console.WriteLine("3. Multiply");
                Console.WriteLine("4. Divide");
                Console.WriteLine("5. Check if prime");
                Console.WriteLine("6. Check if word is palindrome");
                Console.WriteLine("7. Exit");
                Console.WriteLine();

                menuchoice = int.Parse(Console.ReadLine());

                switch (menuchoice)
                {
                case 1:
                    Console.WriteLine("Enter 2 numbers to add: ");
                    Console.WriteLine("Value 1");
                    string addValue1 = Console.ReadLine();
                    Console.WriteLine("Value 2");
                    string addValue2 = Console.ReadLine();
                    double addResult = client.Add(double.Parse(addValue1), double.Parse(addValue2));
                    Console.WriteLine("Add({0},{1}) = {2}", addValue1, addValue2, addResult);
                    Console.WriteLine();
                    break;

                case 2:
                    Console.WriteLine("Enter 2 numbers to subtract: ");
                    Console.WriteLine("Value 1");
                    string subValue1 = Console.ReadLine();
                    Console.WriteLine("Value 2");
                    string subValue2 = Console.ReadLine();
                    double subResult = client.Subtract(double.Parse(subValue1), double.Parse(subValue2));
                    Console.WriteLine("Subtract({0},{1}) = {2}", subValue1, subValue2, subResult);
                    Console.WriteLine();
                    break;

                case 3:
                    Console.WriteLine("Enter 2 numbers to multiply: ");
                    Console.WriteLine("Value 1");
                    string mulValue1 = Console.ReadLine();
                    Console.WriteLine("Value 2");
                    string mulValue2 = Console.ReadLine();
                    double mulResult = client.Multiply(double.Parse(mulValue1), double.Parse(mulValue2));
                    Console.WriteLine("Multiply({0},{1}) = {2}", mulValue1, mulValue2, mulResult);
                    Console.WriteLine();
                    break;

                case 4:
                    Console.WriteLine("Enter 2 numbers to divide: ");
                    Console.WriteLine("Value 1");
                    string divValue1 = Console.ReadLine();
                    Console.WriteLine("Value 2");
                    string divValue2 = Console.ReadLine();
                    double divResult = client.Divide(double.Parse(divValue1), double.Parse(divValue2));
                    Console.WriteLine("Divide({0},{1}) = {2}", divValue1, divValue2, divResult);
                    Console.WriteLine();
                    break;

                case 5:
                    Console.WriteLine("Enter a number to check if it is prime: ");
                    string primeValue1 = Console.ReadLine();

                    bool primeCheck = client.IsPrime(int.Parse(primeValue1));
                    if (primeCheck)
                    {
                        Console.WriteLine("Number {0} is prime", primeValue1);
                        break;
                    }
                    Console.WriteLine("Number {0} is not prime", primeValue1);
                    break;

                case 6:
                    Console.WriteLine("Enter a word or a number to check if it is a palindrome: ");
                    string word = Console.ReadLine();

                    bool checkPalindrome = palClient.IsPalindrome(word);

                    if (checkPalindrome)
                    {
                        Console.WriteLine("The word or number {0} is palindrome", word);
                        break;
                    }
                    Console.WriteLine("The word or number {0} is NOT palindrome", word);
                    break;

                case 7:
                    break;

                default:
                    Console.WriteLine("You did not enter correct selection");
                    break;
                }
            }
        }