Click here to Skip to main content
Click here to Skip to main content

Currency Conversion Using Web Services

, 9 Nov 2006
Rate this:
Please Sign up or sign in to vote.
This article teaches how to use a currency converter Web Service from www.xmethods.net in order to get exchange rates between currencies.

Introduction

I was navigating the web looking for a currency converter and, finally, I found an article by Phil Williams that explains currency conversion using Web Services. So I based this ASP.NET example on that article, and I have tries to make a little bit easier implementation using the ASP.NET environment. You will find the original article here: "Currency Conversion Using Web Services" by Phil Williams. Now, let's focus on the program. This article shows how to implement the currency converter Web Service from http://www.xmethods.net/ in order to get the exchange rates between currencies; the countries list is available in the xmethods website.

Step 1

Start a new ASP.NET project. In the web form, you must create three labels, named Trm (it will show US dollars in Colombian Pesos), Euro (same case but with Euro), Euro_Us (Euro in dollars).

Step 2

The second step is to add the Web Service reference to the third party Web Service, but how?? Go to the Solution Explorer, right click on the root, and click on Add Web Reference.

Sample screenshot

Sorry about the Spanish language in the screenshot, that's my mother language. In this page, you must specify the Web Service URL and click on Go. The URL is http://www.xmethods.net/sd/2001/CurrencyExchangeService.wsdl. Now you will see all the methods available for the Web Service; this one just has one: the GetRate() Web Method.

  • Change the Web Reference name to any string; in this case, it will be Rate_WS.
  • Click on the Add Web Reference button.

Sample screenshot

Add Web Reference Wizard

Now you will be able to invoke the GetRate() method from your program.

Step 3

In the page_load event, add these lines:

protected void Page_Load(object sender, EventArgs e)
{
    try{
        Rate_WS.CurrencyExchangeService to_currency = 
                new Rate_WS.CurrencyExchangeService();
        float euro_us = to_currency.getRate("euro", "united states"); 
        float us_pesos = to_currency.getRate("united states", "colombia"); 
        float euro_pesos = to_currency.getRate("euro", "colombia"); 
        Trm.Text = us_pesos.ToString(); 
        Euro.Text = euro_pesos.ToString(); 
        Euro_Us.Text = euro_us.ToString(); 
    } 
    catch(Exception){} 
}

Change the country names to what you want; the list of countries supported is available at http://www.xmethods.net/. This is an easy implementation for a basic Web Service. Feel free to make any changes.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Britney S. Morales
Web Developer
Colombia Colombia
Web Developer during 3 years and counting, i worked over my school website by two years, right now im webmaster at World Wowan foundation banking in my home city.
 
Please forgive my pictures examples, they are at spanish language because its my mother language.
 

Comments and Discussions

 
GeneralRevision currency convertion PinmemberMember 458891819-Mar-09 4:06 
GeneralRe: Revision currency convertion PinmemberBritney S. Morales19-Mar-09 10:45 
GeneralRe: Revision currency convertion PinmemberMember 458891820-Mar-09 7:14 
GeneralRe: Revision currency convertion PinmemberWilliamAPP18-May-09 11:15 
GeneralAsking UID , Pwd and domain PinmemberMember 20715713-Mar-09 23:08 
Hey Britney whenever i am trying to use your suggested web service it asking me uid,pwd and domain name... can you please suggest me the posible way to avoide it
 
Thanks
QuestionCurrency webservice url not working PinmemberMember 425508824-Dec-08 20:55 
GeneralNO hay problema Pinmembervladi100020-Nov-08 9:17 
GeneralOther URL [modified] PinmemberZwerver14-Sep-08 22:44 
GeneralWeb Service given by u is not working Pinmembervasavi.polisetty13-Jul-08 22:40 
GeneralRe: Web Service given by u is not working Pinmemberjuand1620-Aug-08 11:13 
GeneralWeb Service not connecting.. Pinmembersircutbreaker.com27-Nov-07 7:40 
Generalproblem with the service link Pinmembersandeepram15-Nov-07 2:10 
GeneralGorgeous PinmemberAvi duke17-Jul-07 2:54 
GeneralRe: Gorgeous PinmemberBritney S. Morales28-Sep-07 4:43 
GeneralProblem while implementing same webservice for windows based Device apllication Pinmembershakthi_nandivada26-Jun-07 14:46 
GeneralRe: Problem while implementing same webservice for windows based Device apllication PinmemberBritney S. Morales27-Jun-07 10:57 
GeneralRe: Problem while implementing same webservice for windows based Device apllication Pinmembershakthi_nandivada27-Jun-07 16:32 
Generalnice example Pinmembermarwamay9-Jun-07 23:21 
GeneralRe: nice example PinmemberBritney S. Morales12-Jun-07 9:38 
GeneralGeca PinmemberGeca25-May-07 2:47 
GeneralRe: Geca PinmemberBritney S. Morales12-Jun-07 9:37 
GeneralClean and simple PinmemberMember #328882829-Jan-07 21:28 
Generalhello Pinmemberchernobyl24-Jan-07 16:33 
GeneralRe: hello PinmemberBritney S. Morales25-Jan-07 1:11 
GeneralNice example on web service PinmemberSheel Gohe9-Jan-07 5:37 
GeneralRe: Nice example on web service PinmemberBritney S. Morales9-Jan-07 10:29 
GeneralCode not working PinmemberLeonXWizard1-Dec-06 4:35 
GeneralRe: Code not working PinmemberBritney S. Morales1-Dec-06 5:40 
GeneralI prefer to use this Web Service PinmemberAndri Yadi26-Nov-06 21:14 
GeneralRe: I prefer to use this Web Service PinmemberMunni1128-Sep-07 5:05 
GeneralCode? what Code? I am just here to look at her picture. Pinmemberrishen sukai23-Nov-06 19:54 
JokeI'm still looking at your picture Pinmemberkevferron10-Nov-06 12:27 
GeneralThanks ;) PinmemberPolymorpher27-Sep-06 8:20 
GeneralRe: Thanks ;) Pinmemberleppie9-Nov-06 23:09 
GeneralRe: Thanks ;) PinmemberPolymorpher10-Nov-06 13:54 
GeneralCode not working properly at my end PinmemberEcologic6-Sep-06 21:11 
GeneralRe: Code not working properly at my end [modified] Pinmemberbritneyssssers7-Sep-06 2:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 9 Nov 2006
Article Copyright 2006 by Britney S. Morales
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid