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

Currency Conversion Using Web Services

By , 9 Nov 2006
 

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.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionIt do not worksmemberVimal Upadhyay16 May '13 - 21:20 
Its now working, its waste of time
Reader can contact Author at vimal_up@rediffmail.com

GeneralMy vote of 1memberVimal Upadhyay16 May '13 - 21:20 
It not even working.
QuestionError in codemembervenkat sh15 Oct '12 - 8:37 
im getting error saying nameapace missing for Rate_WS.CurrencyExchangeService
Help me with this!!!
GeneralHello, Code is not working..membermadness12329 Aug '10 - 0:44 
Hello Britney,
 
I have used your code to get rate and used this webservice:
www.freewebs.com/jimmy_cheng/CurrencyExchangeService.wsdl
 
But when I run my application nothing happens, the label still remains the same Label Smile | :)
 
Any Idea???
 
Awaiting for reply,
 
Thanks,
Usman
AnswerAnother solution for this referencememberjaviernovoa8723 Sep '09 - 16:41 
Hi, the web service reference used in this example is unavailable, you try use this http://www.webservicex.net/CurrencyConvertor.asmx[^].
 
Excuse me for my english.
 
Best regards
 
Nelson Javier Novoa Tellez
¡No mas violencia en Colombia!

Generalservice unavailablememberWilliamAPP16 Jul '09 - 6:05 
hi,
 
this service http://www.webservicex.net/CurrencyConvertor.asmx?wsdl is currently unavailable. Can anyone help me?? Anybody knows other available service
 

tnks in advance
Questionis this service currently unavailable?mvpSamir NIGAM25 Jun '09 - 0:11 
Hi Britney S. Morales,

using url: http://www.xmethods.net/sd/2001/CurrencyExchangeService.wsdl[^]
 
i get following message-
 
There was an error downloading 'http://www.xmethods.net/sd/2001/CurrencyExchangeService.wsdl'.
 
The request failed with HTTP status 404: Not Found.
 

is this service currently unavailable?
 
Samir NIGAM
My Articles

GeneralHola justo lo que necesitabamemberMember 335868713 Jun '09 - 5:40 
Hola Britney, que bien me salvaste la patria, de que ciudad eres vos, yo tambien soy de colombia.
Questioncan I ?memberMuneer Safi3 Jun '09 - 20:31 
can i be your student ? Shucks | :->
GeneralCómo es que...memberRugal13 Apr '09 - 20:25 
Sí... cómo es que una belleza como tú, hace lo que a mi me encanta...?
 
Y muy creativa por cierto...
 
Sigue así.
 
Saludos cordiales.
 
Alberto Contreras.
GeneralRevision currency convertionmemberMember 458891819 Mar '09 - 4:06 
Hola,
 
revise la implementacion del currency convertion sin embargo se presentan algunas dudas q te refiero a continuacion:
 

verificando la implementacion de Phil Williams se muestra que no es posible conectarse al servicio http://www.xmethods.net/sd/2001/CurrencyExchangeService.wsdl. Existe alguna implementacion q vos conozcas?
 
si esto es asi que nivel de disponibilidad presenta el servicio web al q haces referencia? puesto q estoy en un desarrollo de un producto para servientrega q requiere una alta disponibilidad del web service.
 

Muchas Gracias de antemano por tu colaboracion
 
William Andres Patarroyo
Developer Engineer
Bogota Colombia
 
wamerikan@gmail.com
GeneralRe: Revision currency convertionmemberBritney S. Morales19 Mar '09 - 10:45 
Hello.
 
Sip, apparently the xmethods web service is not available any longer, but i found this new webservice that is almost the same.
 
The web service address is http://www.webservicex.net/WS/WSDetails.aspx?WSID=10[^]
 
happy day & happy codding Wink | ;)
 
Si, al parecer el servicio prestado por xmethods que soportaba el cambio de monedas fue movido de sitio, si lo quieres utilizar la dirección del descriptor del servicio es http://www.webservicex.net/WS/WSDetails.aspx?WSID=10[^]
 
Alli puedes revisar la descripción del servicio y sus procesos internos.
 
Feliz día & Happy codding Wink | ;)
 
keep Learning and you never will be out of date...

GeneralRe: Revision currency convertionmemberMember 458891820 Mar '09 - 7:14 
Hi,
 
Great, the new address is available
 
thanks for your support
 
William Andres
GeneralRe: Revision currency convertionmemberWilliamAPP18 May '09 - 11:15 
Hi,
 
i've been reviewed this WS http://www.webservicex.net/WS/WSDetails.aspx?WSID=10 and i found some items in order to complement this issue:
 
when this service has been invoked the sintax is:
 
CurrencyConverter.CurrencyConvertor myref = new TestWebService.CurrencyConverter.CurrencyConvertor();
 
and then
 
double convertion= myref2.ConversionRate(TestWebService.CurrencyConverter.Currency.EUR, TestWebService.CurrencyConverter.Currency.COP);
 
the WS deifnition has been modified, something else i got a question.. how long time that service is active? it wouldn't be a good thing that, in any time this service has been disabled like the previous one: http://www.xmethods.net/sd/2001/CurrencyExchangeService.wsdl
however i'm going to research and i will write you
 
thank you
GeneralAsking UID , Pwd and domainmemberMember 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 workingmemberMember 425508824 Dec '08 - 20:55 
Hi,
The link provided by you for currency converter webservice does not work. May be the URL has changed. Can you provide a message regarding the current URL of the webservice.
thanks
shraddha
 
shraddha

GeneralNO hay problemamembervladi100020 Nov '08 - 9:17 
Tambien hay latinos por aqui.
y por cierto estas preciosa!!! Poke tongue | ;-P
GeneralOther URL [modified]memberZwerver14 Sep '08 - 22:44 
Thank you Britney Shucks | :-> , you got me searching for more webservices (since your example didn't function anymore) and i found:
http://www.webservicex.net/CurrencyConvertor.asmx?op=ConversionRate[^]
 
I use it for dollars only so the code then would be something like:
 
public string GetDollars(string sPrice)
    {
        double dPrice;
        try
        {
 
            CurrencyConvertor.CurrencyConvertorSoapClient cs = new CurrencyConvertor.CurrencyConvertorSoapClient();
            if (double.TryParse(sPrice, out dPrice))
            {
                dPrice = dPrice * cs.ConversionRate(CurrencyConvertor.Currency.EUR, CurrencyConvertor.Currency.USD);
            }
            else
            {
                dPrice = 0;
            }
        }
        catch
        {
            dPrice = 0;
        }
        return dPrice.ToString();
    }

 
modified on Monday, September 15, 2008 5:06 AM

GeneralWeb Service given by u is not workingmembervasavi.polisetty13 Jul '08 - 22:40 
Enable to open the url
http://www.xmethods.net/sd/2001/CurrencyExchangeService.wsdl
 
Getting a message "Page not found"
 

Can u give me someother webservice URL for Currency Converter
GeneralRe: Web Service given by u is not workingmemberjuand1620 Aug '08 - 11:13 
Hi,
 
You can use this webservice:
 
www.webservicex.net/CurrencyConvertor.asmx[^]
 
Best Regards,
 

Juan Daniel
GeneralWeb Service not connecting..membersircutbreaker.com27 Nov '07 - 7:40 
I cant seem to access the web service...
 
is there another wsdl to connect to?
 
I wanted to add a converter for my website http://www.torresesterlinas.com
 
I would need to convert costa rican currency to us dollars...
 
thanks for your help,
 
Jeff Smile | :)
Generalproblem with the service linkmembersandeepram15 Nov '07 - 2:10 
Hi,
This is sandeep. I have seen your example for currency conversion in code project example.the service link which you have given is not working now can you please sujjest any other alternative for this to make it work.
 
Thanks Sandeep.

 
Sandeep
GeneralGorgeousmemberAvi duke17 Jul '07 - 2:54 
Hi,
 
I never see such a beautiful face before.
Please send me your Email address and yeah your messenger ID also.
I hope we will in touch soon.
 
buy
Avi duke(back2normal@rediffmail.com) Rose | [Rose] Rose | [Rose] Rose | [Rose]
GeneralRe: GorgeousmemberBritney S. Morales28 Sep '07 - 4:43 
Poke tongue | ;-P , sorry i cant
 
keep Learning and you never will be out of date...

GeneralProblem while implementing same webservice for windows based Device apllicationmembershakthi_nandivada26 Jun '07 - 14:46 
Hi, I tried using the web service in windows console application it was working fine, but when i try using the same code in windows device application i an getting an web exception.
 
Code on buton click:
private void menuItem1_Click(object sender, EventArgs e)
{
net.xmethods.www.CurrencyExchangeService cc = new net.xmethods.www.CurrencyExchangeService();
double d = cc.getRate("Euro", "India");
label1.Text = d.ToString();
}
the same coding is working fine in console application but showing Web Exception in windows device application. Please help me............
Thank You
shakthi


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

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