Consuming a 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‘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:

ws = createObject("webservice","service_here");
param.FromCurrencyCode = USD
param.ToCurrencyCode = EUR
param.Amount = 1;
authXML = XmlNew();
authXML.LicenseInfo = XmlElemNew(authXML,"","LicenseInfo");
authXML.LicenseInfo.RegisteredUser = XmlElemNew(authXML,"","RegisteredUser");
authXML.LicenseInfo.RegisteredUser.UserID= XmlElemNew(authXML,"","UserID");
authXML.LicenseInfo.RegisteredUser.Password = XmlElemNew(authXML,"","Password");
authXML.LicenseInfo.RegisteredUser.UserID.XmlText = "email";
authXML.LicenseInfo.RegisteredUser.Password.XmlText = "PassWord";
output = ws.getConversion(argumentCollection = param);
response = getSoapResponse(ws);

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.