Click here to Skip to main content
Licence CPOL
First Posted 5 Sep 2006
Views 80,226
Bookmarked 35 times

Currency Conversion Using Web Services

By | 9 Nov 2006 | Article
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

Member

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.
 


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralHello, Code is not working.. Pinmembermadness1230:44 29 Aug '10  
AnswerAnother solution for this reference Pinmemberjaviernovoa8716:41 23 Sep '09  
Generalservice unavailable PinmemberWilliamAPP6:05 16 Jul '09  
Questionis this service currently unavailable? PinmvpSamir NIGAM0:11 25 Jun '09  
GeneralHola justo lo que necesitaba PinmemberMember 33586875:40 13 Jun '09  
Questioncan I ? PinmemberMuneer Safi20:31 3 Jun '09  
GeneralCómo es que... PinmemberRugal20:25 13 Apr '09  
GeneralRevision currency convertion PinmemberMember 45889184:06 19 Mar '09  
GeneralRe: Revision currency convertion PinmemberBritney S. Morales10:45 19 Mar '09  
GeneralRe: Revision currency convertion PinmemberMember 45889187:14 20 Mar '09  
GeneralRe: Revision currency convertion PinmemberWilliamAPP11:15 18 May '09  
GeneralAsking UID , Pwd and domain PinmemberMember 207157123:08 3 Mar '09  
QuestionCurrency webservice url not working PinmemberMember 425508820:55 24 Dec '08  
GeneralNO hay problema Pinmembervladi10009:17 20 Nov '08  
GeneralOther URL [modified] PinmemberZwerver22:44 14 Sep '08  
GeneralWeb Service given by u is not working Pinmembervasavi.polisetty22:40 13 Jul '08  
GeneralRe: Web Service given by u is not working Pinmemberjuand1611:13 20 Aug '08  
GeneralWeb Service not connecting.. Pinmembersircutbreaker.com7:40 27 Nov '07  
Generalproblem with the service link Pinmembersandeepram2:10 15 Nov '07  
GeneralGorgeous PinmemberAvi duke2:54 17 Jul '07  
GeneralRe: Gorgeous PinmemberBritney S. Morales4:43 28 Sep '07  
GeneralProblem while implementing same webservice for windows based Device apllication Pinmembershakthi_nandivada14:46 26 Jun '07  
GeneralRe: Problem while implementing same webservice for windows based Device apllication PinmemberBritney S. Morales10:57 27 Jun '07  
GeneralRe: Problem while implementing same webservice for windows based Device apllication Pinmembershakthi_nandivada16:32 27 Jun '07  
Generalnice example Pinmembermarwamay23:21 9 Jun '07  

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.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 9 Nov 2006
Article Copyright 2006 by Britney S. Morales
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid