Пример #1
0
        static void Main(string[] args)
        {
            int result;

            SimpleCalculatorClient proxy1 = new SimpleCalculatorClient();

            result = proxy1.Add(1, 2);

            Console.WriteLine("1 + 2 = " + result);

            proxy1.Close();

            ScientificCalculatorClient proxy2 = new ScientificCalculatorClient();

            result = proxy2.Add(3, 4);
            Console.WriteLine("3 + 4 = " + result);

            result = proxy2.Multiply(5, 6);
            Console.WriteLine("5 * 6 = " + result);

            proxy2.Close();

            Console.ReadLine();
        }
 private void frmSimpleCalculator_Load(object sender, EventArgs e)
 {
     simpleCalc = new SimpleCalculatorClient("WASendpoint");
 }
Пример #3
0
 private void btnResession_Click(object sender, EventArgs e)
 {
     wsClient = new SimpleCalculatorClient("WSHttpBinding_ISimpleCalculator");
 }
Пример #4
0
        private async void btnDivide_Click(object sender, EventArgs e)
        {
            btnDivide.Enabled = false;

            switch (cbType.SelectedIndex)
            {
            case 0:
            default:
            {
                try
                {
                    SimpleCalculatorClient client = new SimpleCalculatorClient("BasicHttpBinding_ISimpleCalculator");
                    lblResult.Text = $"Result: {await client.Divide_1Async(Convert.ToInt32(tbLeft.Text), Convert.ToInt32(tbRight.Text))}";
                }
                catch (FaultException fe)
                {
                    lblResult.Text = $"Result: error, code - {fe.Code.Name}, message - {fe.Message}";
                }
                catch (Exception ex)
                {
                    lblResult.Text = $"Result: {ex.Message}";
                }
                break;
            }

            case 1:
            {
                try
                {
                    lblResult.Text = $"Result: {await wsClient.Divide_1Async(Convert.ToInt32(tbLeft.Text), Convert.ToInt32(tbRight.Text))}";
                }
                catch (FaultException fe)
                {
                    lblResult.Text = $"Result: error, code - {fe.Code.Name}, message - {fe.Message}";
                }
                catch (Exception ex)
                {
                    lblResult.Text = $"Result: {ex.Message}";
                }
                break;
            }

            case 2:
            {
                try
                {
                    SimpleCalculatorClient client = new SimpleCalculatorClient("BasicHttpBinding_ISimpleCalculator");
                    lblResult.Text = $"Result: {await client.Divide_2Async(Convert.ToInt32(tbLeft.Text), Convert.ToInt32(tbRight.Text))}";
                }
                catch (FaultException fe)
                {
                    lblResult.Text = $"Result: error, code - {fe.Code.Name}, message - {fe.Message}";
                }
                catch (Exception ex)
                {
                    lblResult.Text = $"Result: {ex.Message}";
                }
                break;
            }

            case 3:
            {
                try
                {
                    SimpleCalculatorClient client = new SimpleCalculatorClient("BasicHttpBinding_ISimpleCalculator");
                    lblResult.Text = $"Result: {await client.Divide_3Async(Convert.ToInt32(tbLeft.Text), Convert.ToInt32(tbRight.Text))}";
                }
                catch (FaultException fe)
                {
                    lblResult.Text = $"Result: error, code - {fe.Code.Name}, message - {fe.Message}";
                }
                catch (Exception ex)
                {
                    lblResult.Text = $"Result: {ex.Message}";
                }
                break;
            }

            case 4:
            {
                try
                {
                    SimpleCalculatorClient client = new SimpleCalculatorClient("BasicHttpBinding_ISimpleCalculator");
                    lblResult.Text = $"Result: {await client.Divide_4Async(Convert.ToInt32(tbLeft.Text), Convert.ToInt32(tbRight.Text))}";
                }
                catch (FaultException <DivideByZeroFault> fet)
                {
                    lblResult.Text = $"Result: error, code - {fet.Code.Name}, message - {fet.Message}, details - {fet.Detail.Message}";
                }
                catch (FaultException fe)
                {
                    lblResult.Text = $"Result: error, code - {fe.Code.Name}, message - {fe.Message}";
                }
                catch (Exception ex)
                {
                    lblResult.Text = $"Result: {ex.Message}";
                }
                break;
            }

            case 5:
            {
                try
                {
                    ComplexCalculatorClient client = new ComplexCalculatorClient("BasicHttpBinding_IComplexCalculator");
                    lblResult.Text = $"Result: {await client.Divide_1Async(Convert.ToInt32(tbLeft.Text), Convert.ToInt32(tbRight.Text))}";
                }
                catch (FaultException fe)
                {
                    lblResult.Text = $"Result: error, code - {fe.Code.Name}, message - {fe.Message}";
                }
                catch (Exception ex)
                {
                    lblResult.Text = $"Result: {ex.Message}";
                }
                break;
            }

            case 6:
            {
                try
                {
                    ComplexCalculatorClient client = new ComplexCalculatorClient("BasicHttpBinding_IComplexCalculator");
                    lblResult.Text = $"Result: {await client.Divide_2Async(Convert.ToInt32(tbLeft.Text), Convert.ToInt32(tbRight.Text))}";
                }
                catch (FaultException fe)
                {
                    lblResult.Text = $"Result: error, code - {fe.Code.Name}, message - {fe.Message}";
                }
                catch (Exception ex)
                {
                    lblResult.Text = $"Result: {ex.Message}";
                }
                break;
            }
            }

            btnDivide.Enabled = true;
        }
Пример #5
0
 private void Form1_Load(object sender, EventArgs e)
 {
     wsClient             = new SimpleCalculatorClient("WSHttpBinding_ISimpleCalculator");
     cbType.SelectedIndex = 0;
 }