コード例 #1
0
        private void calcCost_Click(object sender, RoutedEventArgs e)
        {
            ProductsServiceClient proxy = new ProductsServiceClient();

            try
            {
                int     prodID = Int32.Parse(this.productID.Text);
                int     number = Int32.Parse(this.howMany.Text);
                decimal cost   = proxy.HowMuchWillItCost(prodID, number);
                this.totalCost.Content = String.Format("{0:C}", cost);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error obtaining cost: " +
                                ex.Message, "Error", MessageBoxButton.OK,
                                MessageBoxImage.Error);
            }
            finally
            {
                if (proxy.State == System.ServiceModel.CommunicationState.Faulted)
                {
                    proxy.Abort();
                }
                else
                {
                    proxy.Close();
                }
            }
        }