Posted by : sinhalamp3 Monday, October 13, 2014


Consume a Web Service in ASP.NET

//-------------------------------------------Windows Form -------------------------------
private void Form1_Load(object sender, EventArgs e)
        {
foreach (var item in Enum.GetValues(typeof(ServiceReference1.Currency)))
            {
                comboBox1.Items.Add(item);
                comboBox2.Items.Add(item);
            }
}


private void button1_Click(object sender, EventArgs e)
        {
            String one = comboBox1.SelectedItem.ToString();
            String two = comboBox2.SelectedItem.ToString();

            int three = Int32.Parse(textBox1.Text);

            ServiceReference1.Currency cd = (ServiceReference1.Currency)Enum.Parse(typeof(ServiceReference1.Currency), one);
            ServiceReference1.Currency cd1 = (ServiceReference1.Currency)Enum.Parse(typeof(ServiceReference1.Currency), two);
            ServiceReference1.CurrencyConvertorSoapClient ws = new ServiceReference1.CurrencyConvertorSoapClient("CurrencyConvertorSoap");
            double ds = ws.ConversionRate(cd, cd1);
            double result = ds * three;
            textBox2.Text = result.ToString();

        }
---------------------------------------------------------------------------
----------------------------------------ASP .NET --------------------------

protected void Page_Load(object sender, EventArgs e)
 {
            string[] names = Enum.GetNames(typeof(ServiceReference1.Currency));
            int[] values = (int[])Enum.GetValues(typeof(ServiceReference1.Currency));
            for (int i = 0; i < names.Length; i++)
            {
                DropDownList1.Items.Add(
                   new ListItem(
                     names[i],
                     values[i].ToString()
                    )    
        );
            }

            for (int i = 0; i < names.Length; i++)
            {
                DropDownList2.Items.Add(
                   new ListItem(
                     names[i],
                     values[i].ToString()
                    )
        );
            }




                //foreach (var item in Enum.GetValues(typeof(ServiceReference1.Currency)))
                //{
                //    to.Items.Add(item);


                //}
         
        }

-----------------------------------------------------------------------------------------------
        protected void Button1_Click1(object sender, EventArgs e)
        {
            try
            {

                ServiceReference1.CurrencyConvertorSoapClient client = new ServiceReference1.CurrencyConvertorSoapClient();

                ServiceReference1.Currency fromValue = (ServiceReference1.Currency)Enum.Parse(typeof(ServiceReference1.Currency), DropDownList1.SelectedItem.ToString());

                ServiceReference1.Currency toValue = (ServiceReference1.Currency)Enum.Parse(typeof(ServiceReference1.Currency), DropDownList2.SelectedItem.ToString());

                double currencyValue = Convert.ToDouble(TextBox1.Text.ToString());

                double finalValue = currencyValue * (Convert.ToDouble(client.ConversionRate(fromValue, toValue).ToString()));

                Label1.Text = finalValue.ToString();

             
             

            }
            catch (Exception ex)
            {
            }
        }
}

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Popular Post

Blogger templates

lakshika345@gmail.com. Powered by Blogger.

- Copyright © mp3s for you -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -