Every five minutes, a business in the U.S. catches fire, someone in the UK swears, and a clock that took 5 years and Â£1 million to build before being unveiled by none other than Stephen Hawking, finally 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 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 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."
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 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.