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


GeneralRe: Problem while implementing same webservice for windows based Device apllicationmemberBritney S. Morales27 Jun '07 - 10:57 
Can you write the exception sentence over here???,
 
keep Learning and you never will be out of date...

GeneralRe: Problem while implementing same webservice for windows based Device apllicationmembershakthi_nandivada27 Jun '07 - 16:32 
even using try catch block...doesn't work..still it is showing Web Exception....
Generalnice examplemembermarwamay9 Jun '07 - 23:21 
thx was just lookin for a web service doin this Smile | :)
GeneralRe: nice examplememberBritney S. Morales12 Jun '07 - 9:38 
I fell really good, when i help people to solve their problems.
 
keep Learning and you never will be out of date...

GeneralGecamemberGeca25 May '07 - 2:47 
La programadora mas maja que he visto en mi vida !!!Smile | :)
GeneralRe: GecamemberBritney S. Morales12 Jun '07 - 9:37 
Vamos, que hay mujeres en el mundillo de la informática tan lindas como yo... Poke tongue | ;-P
 
keep Learning and you never will be out of date...

GeneralClean and simplememberMember #328882829 Jan '07 - 21:28 
A clean and simple example Smile | :)
Just the way it should be
Generalhellomemberchernobyl24 Jan '07 - 16:33 
hello
GeneralRe: hellomemberBritney S. Morales25 Jan '07 - 1:11 
Nice comment Laugh | :laugh:
 
keep Learning and you never will be out of date...

GeneralNice example on web servicememberSheel Gohe9 Jan '07 - 5:37 
Hi,
Your article on web services is impressive. Can you provide me some more examples or liks to sites from where i can find out some advance topics on web services.
 
Thanks & Regards
Sheel Gohe
 
Sheel Gohe

GeneralRe: Nice example on web servicememberBritney S. Morales9 Jan '07 - 10:29 
Thanks Blush | :O , but this example is far to be an advance web service topic Laugh | :laugh: ,
 
So, about your request, i based my Web services studies using the MSDN microsoft library, here i write you some links that you can visit
 
Understanding the Web Services
 
http://msdn.microsoft.com/webservices/webservices/understanding/default.aspx[^]
 
Returning Objects From WebServices
 
http://ryanfarley.com/blog/archive/2004/05/26/737.aspx[^]
 
have fun Laugh | :laugh:

 
keep Learning and you never will be out of date...

GeneralCode not workingmemberLeonXWizard1 Dec '06 - 4:35 
I did all what u posted and when i run the program,it doesn't work.It does not give any exception,error, nothing just nothing
 
Leon Kouchica

GeneralRe: Code not workingmemberBritney S. Morales1 Dec '06 - 5:40 
The code works at all, Maybe you are experimenting a timeout exception, try showing the message Exception.
 

catch (Exception ex) {
Message.Text = ex.Message;
}
 
Rose | [Rose]
 
keep Learning and you never will be out of date...

GeneralI prefer to use this Web ServicememberAndri Yadi26 Nov '06 - 21:14 
I prefer to use WS from this link:
http://www.webservicex.net/WS/WSDetails.aspx?CATID=2&WSID=10
 
It's much easier..Instead of writing "euro" as method paramater, this WS method using enumeration as params. So, u don't have to remember currency string as method params.
 
Btw, Britney...u'r so gorgeous for a developer. May be we can talk much more..Please contact me at my email below. Thanks.
 
Andri Yadi
==========
andri@pastel.co.id
Yahoo ID: method_overriding
GeneralRe: I prefer to use this Web ServicememberMunni1128 Sep '07 - 5:05 
Hello even i am using this webservice but i am getting some errors can u plz post the code of urs. I am very new to webservices n have to implement in my project(no other dotnet developers in my team).. Plz help me out
GeneralCode? what Code? I am just here to look at her picture.memberrishen sukai23 Nov '06 - 19:54 
.
JokeI'm still looking at your picturememberkevferron10 Nov '06 - 12:27 
I will read your article right when i'm done.
 

GeneralThanks ;)memberPolymorpher27 Sep '06 - 8:20 
I am trying to learn ASP and this was helpfull. Thank You!
 
Pablo
Sometimes I think there's no reason to get out of bed . . . then I feel wet, and I realize there is.

GeneralRe: Thanks ;)memberleppie9 Nov '06 - 23:09 
Hehe, funny sig Smile | :)
 

GeneralRe: Thanks ;)memberPolymorpher10 Nov '06 - 13:54 
LOL, I found it on a homer simpson site...do you live in Columbia Missouri?
 
Pablo
Sometimes I think there's no reason to get out of bed . . . then I feel wet, and I realize there is.

GeneralCode not working properly at my endmemberEcologic6 Sep '06 - 21:11 
hi there,
I have used that web service. I added a web reference and I created a
object of the class specified. It gives the following error
"The underlying connection was closed: A connection that was expected to
be kept alive was closed by the server"
any idea?
Thanks
 
Manmohan Singh Sarwara
GeneralRe: Code not working properly at my end [modified]memberbritneyssssers7 Sep '06 - 2:40 
Check the contries name's list, The country name must to be exactly like appears at the list (string and lowercase), the return is always a float number
 

The countries list and all the thecnical reference is at http://www.xmethods.net/ at the end of the page, the link is Currency Exchange Rate
 

To deploy the error just try one WS Method invoice
 
Rate_WS.CurrencyExchangeService to_currency = new Rate_WS.CurrencyExchangeService();
float euro_us = to_currency.getRate("euro", "united states");
Euro_Us.Text = euro_us.ToString();
 
Keep Learning...

 

-- modified at 8:48 Thursday 7th September, 2006
 
ff

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.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