Exemple #1
0
        static void Main(string[] args)
        {
            var sum = 0;
            string serviceUrl;

            Console.WriteLine("Welcome to the Calculator client.");
            Console.Write("Use [w]eb or [c]onsole endpoint? ");
            switch (Console.ReadLine())
            {
                case "w":
                    serviceUrl = "http://localhost:51234/Calculator.svc";
                    break;
                case "c":
                    serviceUrl = "http://localhost:12345/";
                    break;
                default:
                    Console.WriteLine("Not a valid key.");
                    Main(null);
                    return;
            }

            while (true)
            {
                Console.WriteLine("Current sum: {0}. Please type a new number.", sum);
                var input = int.Parse(Console.ReadLine());
                Console.Write("Connecting to '{0}' to calculate {1} + {2}", serviceUrl, sum, input);

                using (var calculatorProxy = new CalculatorServiceProxy(serviceUrl))
                {
                    sum = calculatorProxy.Add(input, sum);
                }

                Console.WriteLine(" = {0}", sum);
            }
        }
Exemple #2
0
 static void Main(string[] args)
 {
     ICalculator calculator = new CalculatorServiceProxy();
     for (int i = 0; i < 1000; i++)
     {
         calculator.Add(1, 2);
         Console.WriteLine("第{0}个服务代理调用成功!", i + 1);
     }
 }
Exemple #3
0
        protected void Calculate(object sender, EventArgs e)
        {
            Calculation dto = new Calculation
            {
                Operand1 =
                    float.Parse(operand1.Text)
            };

            try
            {
                dto.Operand2 = float.Parse(operand2.Text);
            }
            catch (FormatException)
            {
                dto.Operand2 = 0;
            }

            Calculation resultDto;
            ICalculator proxy = new CalculatorServiceProxy();

            try
            {
                switch (operation.SelectedValue)
                {
                case "Add":
                    resultDto = proxy.Add(dto);
                    break;

                case "Subtract":
                    resultDto = proxy.Subtract(dto);
                    break;

                case "Multiply":
                    resultDto = proxy.Multiply(dto);
                    break;

                case "Divide":
                    resultDto = proxy.Divide(dto);
                    break;

                case "SquareRoot":
                    resultDto = proxy.SquareRoot(dto);
                    break;

                default:
                    throw new NotImplementedException();
                }
                result.Text = resultDto.Result.ToString();
                PopulateCalculationAudit();
            }
            catch (Exception exception)
            {
                statusMessage.Text = exception.Message;
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            CalculatorServiceProxy servieProxy1 = new CalculatorServiceProxy("WSHttpBinding_ICalculator");

            int addResult = servieProxy1.Add(1, 2);

            CalculatorServiceProxy serviceProxy2 = new CalculatorServiceProxy("WSHttpBinding_ICalculator1");

            int subtractResult = serviceProxy2.Subtract(1, 2);

            Console.ReadLine();
        }
        protected void PopulateCalculationAudit()
        {
            ICalculator proxy = new CalculatorServiceProxy();

            calculationAudits.Items.Clear();
            string[] audits = proxy.GetCalculationAudits();
            Array.Reverse(audits);
            Array.ForEach(audits, text =>
                          calculationAudits.Items.Add(text));
            if (calculationAudits.Items.Count == 0)
            {
                calculationAudits.Items.Add("<No Calculations Have Been Submitted Yet > ");
            }
        }
Exemple #6
0
        static void Main(string[] args)
        {
            var    sum = 0;
            string serviceUrl;

            Console.WriteLine("Welcome to the Calculator client.");
            Console.Write("Use [w]eb or [c]onsole endpoint? ");
            switch (Console.ReadLine())
            {
            case "w":
                serviceUrl = "http://localhost:51234/Calculator.svc";
                break;

            case "c":
                serviceUrl = "http://localhost:12345/";
                break;

            default:
                Console.WriteLine("Not a valid key.");
                Main(null);
                return;
            }

            while (true)
            {
                Console.WriteLine("Current sum: {0}. Please type a new number.", sum);
                var input = int.Parse(Console.ReadLine());
                Console.Write("Connecting to '{0}' to calculate {1} + {2}", serviceUrl, sum, input);

                using (var calculatorProxy = new CalculatorServiceProxy(serviceUrl))
                {
                    sum = calculatorProxy.Add(input, sum);
                }

                Console.WriteLine(" = {0}", sum);
            }
        }