Beispiel #1
0
        static void Main(string[] args)
        {
            var ServiceHost = new ServiceHost(typeof(CalculatorService));

            ServiceHost.Open();

            var Client = new CalculatorServiceClient();

            try
            {
                //Client.Divide(1, 0);
                var Result = Client.WeighPickle(new Pickle {
                    Name = "Bob", Bumps = 12
                });
                Console.WriteLine(Result);
                Client.Close();
            }
            catch (Exception)
            {
                Client.Abort();
                throw;
            }


            Console.ReadLine();
        }
Beispiel #2
0
        private void CalculateResults()
        {
            CalculatorServiceClient proxy = null;
            try
            {
                double value1 = Convert.ToDouble(textValue1.Text);
                double value2 = Convert.ToDouble(textValue2.Text);

                string endpointName;
                if (ComboBoxServiceConnection.SelectedIndex == 0)
                    endpointName = "CalculatorService";
                else
                    endpointName = "RouterService";
                proxy = new CalculatorServiceClient(endpointName);
                labelAddResult.Text = proxy.Add(value1, value2).ToString();
                labelSubResult.Text = proxy.Subtract(value1, value2).ToString();
                labelMultResult.Text = proxy.Multiply(value1, value2).ToString();
                if (value2 != 0.00)
                    labelDivResult.Text = proxy.Divide(value1, value2).ToString();
                else
                    labelDivResult.Text = "Divide by 0";
            }
            catch (FormatException)
            {
                MessageBox.Show("Invalid numeric value, cannot calculate", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (TimeoutException)
            {
                if (proxy != null)
                    proxy.Abort();
                MessageBox.Show("Timeout - cannot connect to service", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (CommunicationException)
            {
                if (proxy != null)
                    proxy.Abort();
                MessageBox.Show("Unable to communicate with the service", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                if (proxy != null)
                    proxy.Close();
            }
        }
        static void Main(string[] args)
        {
            var ServiceHost = new ServiceHost(typeof(CalculatorService));
            ServiceHost.Open();

            var Client = new CalculatorServiceClient();
            try
            {
                //Client.Divide(1, 0);
                var Result = Client.WeighPickle(new Pickle { Name = "Bob", Bumps = 12 });
                Console.WriteLine(Result);
                Client.Close();
            }
            catch (Exception)
            {
                Client.Abort();
                throw;
            }

            Console.ReadLine();
        }
Beispiel #4
0
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            CalculatorServiceClient client = new CalculatorServiceClient("Username");

            try
            {
                client.ClientCredentials.UserName.UserName = txtUsername.Text;
                client.ClientCredentials.UserName.Password = txtPassword.Text;
                client.Open();
                client.Login();
                Form form = new Calculator(txtUsername.Text, txtPassword.Text);
                this.Hide();
                form.Show();
                client.Close();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.InnerException.Message);
                client.Abort();
            }
        }