示例#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);

            // 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();
        }
示例#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 = 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();
        }
示例#3
0
        private 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.WriteLine("Calc.exe");
            client.Calc();
            Console.ReadKey();


            //Step 3: Closing the client gracefully closes the connection and cleans up resources.
            client.CloseCalc();

            client.Close();
        }
示例#4
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();
        }
示例#5
0
        static void Main(string[] args)
        {
            CalculatorClient client = new CalculatorClient();
            List <Fruit>     fruits = new List <Fruit>();
            Fruit            Apple  = new Fruit();
            Fruit            Pear   = new Fruit();
            Fruit            Orange = new Fruit();

            Pear.Name   = "Pear";
            Orange.Name = "Orange";
            Apple.Name  = "Apple";

            client.AddAFruit(fruits, Orange);
            // fruits = client.AddAFruit(fruits, Pear);
            //fruits = client.AddAFruit(fruits, Apple);

            Console.WriteLine("Adding {Apple},{Pear},{Orange} to Fridge");
            //int index = 2;

            //client.RemoveAFruit(fruits, index);

            //client.Total(fruits);
        }
示例#6
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();
        }
示例#7
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;
                }
            }
        }
示例#8
0
 private void Form1_Load(object sender, EventArgs e)
 {
     _client = new CalculatorClient();
 }