5 Minute Developer: How to Build a Currency Converter in 5 Minutes
First Published Monday, 8th February 2010 06:08 pm from Xand : ChasCooper
The opinions expressed by this blogger and those providing comments are theirs alone, this does not reflect the opinion of Automated Trader or any employee thereof. Automated Trader is not responsible for the accuracy of any of the information supplied by this article.
height="61" width="51" />
Every
five minutes, a business in the U.S.
href="http://crm.cr.nps.gov/archive/24-08/24-08-5.pdf"
target="_blank">catches fire, someone in the UK
href="http://www.telegraph.co.uk/news/uknews/6230569/Swear-words-heard-once-every-five-minutes.html"
target="_blank">swears, and a clock that took 5
years and £1 million to build before being unveiled by none
other than Stephen Hawking, finally
href="http://news.bbc.co.uk/2/hi/7625815.stm"
target="_blank">tells the time accurately for a
second or two.
What will you do with your next
5 minutes?
Here's a thought: Why not build a
href="http://www.xignite.com/forex/web-service/2000106.html">real-time
forex currency converter? Sound like fun? If so, give
it a try using the steps below. Or, if you'd rather
leave all the fun to someone else, why not just href="http://www.xignite.com/forex/web-service/2000106.html"
target="_self">watch a video of us doing
it?
Here's how
it's done:
Step 1: Start a new Windows
application project in Visual Studio.
Step 2: Create a Web
reference to http://www.xignite.com/xCurrencies.asmx?WSDL and
call it XigniteCurrenciesService.
Step 3: On the Form1
design, drag and drop 3 text boxes, 2 labels, and a button,
arranging them as shown in the picture. From left to right, give
the text boxes the following names and default text:
inputBaseAmount defaulting to 1000, inputBaseSymbol defaulting to
USD, inputQuoteSymbol defaulting to EUR. One label should have a
big equal sign in it and the other should have the name of
labelQuoteAmount and zero for its text property. The button
should read "Convert."
class="aligncenter"
src="http://cdn.xignite.com/blog/02_01_10/5min_currency_converter_v1a.png"
alt="Real-Time Forex Currency Converter Built in 5 Minutes"
/>
Step 4:
Double-click the button to create its click event
handler, and give it the following 3 lines of code:
XigniteCurrenciesService.XigniteCurrencies
XigniteCurrenciesWebService = new
XigniteCurrenciesService.XigniteCurrencies();
XigniteCurrenciesService.ExchangeConversion Quote =
XigniteCurrenciesWebService.ConvertRealTimeValue(inputBaseSymbol.Text,
inputQuoteSymbol.Text,
double.Parse(inputBaseAmount.Text));
labelQuoteAmount.Text =
Quote.Result.ToString();
Step 5:
Compile and run.
Authentication trouble? If
you get an authentication error, it means you're not
being authenticated from a cookie or your IP address.
Don't worry. Just add 3 more lines after the first line
of code to pass your authentication key through SOAP. Be sure to
replace MYAUTHENTICATIONKEY with your own Xignite account
authentication key. (Don't have an authentication key? Just href="http://www.xignite.com/forex/getting-started/2000111.html"
target="_self">sign up to get one. Your e-mail will
be your initial authentication
key.)
XigniteCurrenciesService.Header
objHeader = new XigniteCurrenciesService.Header();
objHeader.Username =
"MYAUTHENTICATIONKEY";
XigniteCurrenciesWebService.HeaderValue =
objHeader;
Congratulations!
You just spent the last five minutes far more
productively than one U.S. business, one citizen of the UK, and
one very expensive but very inaccurate clock.
Share and
title="Digg">
src="http://xignite.web-services-blog.com/wp-content/plugins/sociable/images/digg.png"
title="Digg" alt="Digg" class="sociable-hovers" />
title="del.icio.us" alt="del.icio.us" class="sociable-hovers"
title="Facebook" alt="Facebook" class="sociable-hovers"
title="Google" alt="Google" class="sociable-hovers"
title="Live">
src="http://xignite.web-services-blog.com/wp-content/plugins/sociable/images/live.png"
title="Live" alt="Live" class="sociable-hovers" />
title="Reddit" alt="Reddit" class="sociable-hovers"
title="Slashdot" alt="Slashdot" class="sociable-hovers"
title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers"
title="Technorati" alt="Technorati" class="sociable-hovers"
title="TwitThis" alt="TwitThis" class="sociable-hovers"
title="LinkedIn" alt="LinkedIn" class="sociable-hovers"
title="E-mail this story to a friend!" alt="E-mail this story to
a friend!" class="sociable-hovers" />
border="0">
src="http://feeds.feedburner.com/~r/Xignite/~4/DDDXjiT9b98"
height="1" width="1" />


