Consuming the Live Currency Conversion Web Service using C#

There is a live .NET Web Service which offers all the curreny conversion eg. USD to INR etc.

This WS is available via live URL http://www.webservicex.net/CurrencyConvertor.asmx
This WS has a class CurrecnyConvertor which exposes one Function named ConversionRate and an enum named Currency which exposed the list of all the currencies like USD, INR, AED etc.

As you know Currency conversion will depend on two parameters ConvertFrom and ConvertTo and so the same is expected to be passsed while invoking ConversionRate function.

Here is a detailed list of steps:

  1. Add a Web Reference to http://www.webservicex.net/CurrencyConvertor.asmx
  2. Rename the Reference name to something more friendly like CurrencyConversionWS
  3. In your project create an instance of the added Web service reference
  4. On the created object invoke the ConversionRate function.
  5. As mentioned above there is an enum which lists all the currencies and so access it directly from the object created.
  6. Save the result into a double variable and multiply with your passed amount.
  7. Multiply the amount you want to convert to the received conversion rate.

Here is the code you will require to have it all working:

CurrencyConversionWS.CurrencyConvertor objWS = new CurrencyConversionWS.CurrencyConvertor();
double usdToinr = objWS.ConversionRate(CurrencyConversionWS.Currency.USD, CurrencyConversionWS.Currency.INR);
double totalAmount = usdToinr * Double.Parse(textBox1.Text);
MessageBox.Show(totalAmount.ToString(),"Total Indian Rupees");

This is how it will look like:

CurrencyConvertor.jpg

Ebook Download
View all
Learn
View all