Consuming a StrikeIron.com Webservice in ColdFusion

Built out a currency converter for a project we are working on over here. After looking at a couple options, decided to use StrikeIron.com‘s currency web service. It was a bit tricky to put together, as I was having no luck using the <cfinvoke> tags, and trying to pass the authentication info as arguments. Finally broke down and looked at their documentation.Seem they need the authentication info to be passed as an XML obj in each request header. This is the code that finally worked for me:

<cfscript>
ws = createObject("webservice","service_here");
param.FromCurrencyCode = USD
param.ToCurrencyCode = EUR
param.Amount = 1;
authXML = XmlNew();
authXML.LicenseInfo = XmlElemNew(authXML,"http://strikeiron.com","LicenseInfo");
authXML.LicenseInfo.RegisteredUser = XmlElemNew(authXML,"http://strikeiron.com","RegisteredUser");
authXML.LicenseInfo.RegisteredUser.UserID= XmlElemNew(authXML,"http://strikeiron.com","UserID");
authXML.LicenseInfo.RegisteredUser.Password = XmlElemNew(authXML,"http://strikeiron.com","Password");
authXML.LicenseInfo.RegisteredUser.UserID.XmlText = "email";
authXML.LicenseInfo.RegisteredUser.Password.XmlText = "PassWord";
addSoapRequestHeader(ws,"http://strikeiron.com","LicenseInfo",authXML);
output = ws.getConversion(argumentCollection = param);
response = getSoapResponse(ws);
</cfscript>

About Curious Minds
We are a web development firm in New York and Chicago, providing development resources and consulting for websites and mobile apps since 2004.