Consuming a Web Service for Currency Exchange Rate

Consuming Web Services Add comments

Using CFINVOKE to fetch data from a webservice isn’t so difficult, though the free services can be a bit laggy or suffer downtime.  For this example, I pull the currency exchange rate from the webservice on a schedule so I can store it in a database.  I pull it from the database as needed, so it’s always fast and reliable.

Here’s an example of consuming the service.  In this example, I’m using the Currency Convertor over at webservicex.net.

<cfinvoke 
	webservice = "http://www.webservicex.net/CurrencyConvertor.asmx?wsdl"
	method = "ConversionRate"
	FromCurrency = "USD" 
	ToCurrency = "EUR"
	returnVariable = "USD2EUR"
	/>

I always like to wrap my webservices in a CFTRY so I can log any failures in the CFCATCH.

Pretty easy, eh?  Do you have a favorite webservice that you like to consume?  I should probably give another example at a later date for the weather, as I’m always having to look that one up again.

2 responses to “Consuming a Web Service for Currency Exchange Rate”

  1. Dani Szwarc Says:
    Hello, I'm writing from Montreal. Can I ask you how to implement this code? Let's say I provide pricing in Canadian Dollars and the client wants to be able to change the currency the pricing is displayed. Can I apply this? Thank you!
  2. Dani Szwarc Says:
    Thanks for the code. I was able to understand how a web service work and how to implement it. Thanks for this.

Leave a Reply

Leave this field empty:

Powered by Mango Blog. Initial Template Design and Icons by N.Design Studio, modified by Michael Cummins.