Click here to Skip to main content
16,018,805 members
Articles / Web Development / ASP.NET

Currency Conversion Using Web Services

Rate me:
Please Sign up or sign in to vote.
3.17/5 (20 votes)
9 Nov 2006CPOL2 min read 194.7K   35   47
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:

C#
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)


Written By
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

 
QuestionIt do not works Pin
Vimal Upadhyay16-May-13 21:20
Vimal Upadhyay16-May-13 21:20 
GeneralMy vote of 1 Pin
Vimal Upadhyay16-May-13 21:20
Vimal Upadhyay16-May-13 21:20 
QuestionError in code Pin
venkat sh15-Oct-12 8:37
venkat sh15-Oct-12 8:37 
GeneralHello, Code is not working.. Pin
madness12329-Aug-10 0:44
madness12329-Aug-10 0:44 
AnswerAnother solution for this reference Pin
javiernovoa8723-Sep-09 16:41
javiernovoa8723-Sep-09 16:41 
Generalservice unavailable Pin
WilliamAPP16-Jul-09 6:05
WilliamAPP16-Jul-09 6:05 
Questionis this service currently unavailable? Pin
Samir NIGAM25-Jun-09 0:11
Samir NIGAM25-Jun-09 0:11 
GeneralHola justo lo que necesitaba Pin
Juan MM13-Jun-09 5:40
Juan MM13-Jun-09 5:40 
Questioncan I ? Pin
Muneer Safi3-Jun-09 20:31
Muneer Safi3-Jun-09 20:31 
can i be your student ? Shucks | :-\
GeneralCómo es que... Pin
Rugal13-Apr-09 20:25
Rugal13-Apr-09 20:25 
GeneralRevision currency convertion Pin
WilliamAPP19-Mar-09 4:06
WilliamAPP19-Mar-09 4:06 
GeneralRe: Revision currency convertion Pin
Britney S. Morales19-Mar-09 10:45
Britney S. Morales19-Mar-09 10:45 
GeneralRe: Revision currency convertion Pin
WilliamAPP20-Mar-09 7:14
WilliamAPP20-Mar-09 7:14 
GeneralRe: Revision currency convertion Pin
WilliamAPP18-May-09 11:15
WilliamAPP18-May-09 11:15 
GeneralAsking UID , Pwd and domain Pin
Member 20715713-Mar-09 23:08
Member 20715713-Mar-09 23:08 
QuestionCurrency webservice url not working Pin
Member 425508824-Dec-08 20:55
Member 425508824-Dec-08 20:55 
GeneralNO hay problema Pin
vladi100020-Nov-08 9:17
vladi100020-Nov-08 9:17 
GeneralOther URL [modified] Pin
Zwerver14-Sep-08 22:44
Zwerver14-Sep-08 22:44 
GeneralWeb Service given by u is not working Pin
vasavi.polisetty13-Jul-08 22:40
vasavi.polisetty13-Jul-08 22:40 
GeneralRe: Web Service given by u is not working Pin
juand1620-Aug-08 11:13
juand1620-Aug-08 11:13 
GeneralWeb Service not connecting.. Pin
sircutbreaker.com27-Nov-07 7:40
sircutbreaker.com27-Nov-07 7:40 
Generalproblem with the service link Pin
sandeepram15-Nov-07 2:10
sandeepram15-Nov-07 2:10 
GeneralGorgeous Pin
Avi duke17-Jul-07 2:54
Avi duke17-Jul-07 2:54 
GeneralRe: Gorgeous Pin
Britney S. Morales28-Sep-07 4:43
Britney S. Morales28-Sep-07 4:43 
GeneralProblem while implementing same webservice for windows based Device apllication Pin
shakthi_nandivada26-Jun-07 14:46
shakthi_nandivada26-Jun-07 14:46 

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

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