Exemple #1
0
        static void AInvocateCalclatorServiceViaConfiguration()
        {
            Console.WriteLine("Invocate self-host calculator service ");

            #region Invocate Self-host service
            using (CalculatorClient calculator_http = new CalculatorClient("selfHostEndpoint_http"))
            {
                using (CalculatorClient calculator_tcp = new CalculatorClient("selfHostEndpoint_tcp"))
                {
                    try
                    {
                        Console.WriteLine("Begin to invocate calculator service via http transport ");
                        Console.WriteLine("x + y = {2} where x = {0} and y = {1}", 1, 2, calculator_http.Add(1, 2));

                        Console.WriteLine("Begin to invocate calculator service via tcp transport ");
                        Console.WriteLine("x + y = {2} where x = {0} and y = {1}", 1, 2, calculator_tcp.Add(1, 2));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            #endregion

            Console.WriteLine("\n\nInvocate IIS-host calculator service ");

            #region Invocate IIS-host service
            using (CalculatorClient calculator = new CalculatorClient("iisHostEndpoint"))
            {
                try
                {
                    Console.WriteLine("Begin to invocate calculator service via http transport ");
                    Console.WriteLine("x + y = {2} where x = {0} and y = {1}", 1, 2, calculator.Add(1, 2));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            #endregion
        }
Exemple #2
0
        static void InvocateCalclatorServiceViaConfiguration()
        {
            Binding httpBinding = new BasicHttpBinding();
            Binding tcpBinding  = new NetTcpBinding();

            EndpointAddress httpAddress         = new EndpointAddress("http://localhost:8888/generalCalculator");
            EndpointAddress tcpAddress          = new EndpointAddress("net.tcp://localhost:9999/generalCalculator");
            EndpointAddress httpAddress_iisHost = new EndpointAddress("http://localhost/wcfservice/GeneralCalculatorService.svc");

            Console.WriteLine("Invocate self-host calculator service ");

            using (CalculatorClient calculator_http = new CalculatorClient(httpBinding, httpAddress)) {
                using (CalculatorClient calculator_tcp = new CalculatorClient(tcpBinding, tcpAddress)) {
                    try {
                        Console.WriteLine("Begin to invocate calculator service via http transport ");
                        Console.WriteLine("x + y = {2} where x = {0} and y = {1}", 1, 2, calculator_http.Add(1, 2));

                        Console.WriteLine("Begin to invocate calculator service via tcp transport ");
                        Console.WriteLine("x + y = {2} where x = {0} and y = {1}", 1, 2, calculator_tcp.Add(1, 2));
                    }
                    catch (Exception ex) {
                        Console.WriteLine(ex.Message);
                    }
                }
            }

            Console.WriteLine("\n\nInvocate IIS-host calculator service ");

            using (CalculatorClient calculator = new CalculatorClient(httpBinding, httpAddress_iisHost))
            {
                try
                {
                    Console.WriteLine("Begin to invocate calculator service via http transport ");
                    Console.WriteLine("x + y = {2} where x = {0} and y = {1}", 1, 2, calculator.Add(1, 2));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Exemple #3
0
        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();
        }
Exemple #5
0
        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();
        }