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.
Recent Comments