Click here to close now.


You will be redirected in 30 seconds or close now.

ColdFusion Authors: Yakov Fain, Maureen O'Gara, Nancy Y. Nee, Tad Anderson, Daniel Kaar

Related Topics: ColdFusion

ColdFusion: Article

How May I Be of Web Service?

How May I Be of Web Service?

There is a phenomenon that appears to be unique to our industry - something I call buzzword du jour. On a regular basis a new buzzword (usually accompanied by a series of acronyms) appears on the front pages of the trade rags proclaiming to be "the future" - the message being "jump on board or become obsolete." This happens so frequently that many of us are becoming immune to it all, and in doing so are running the risk of missing something important when (or if) it happens. Which brings us to Web services.

What's the Deal?
If you are to believe the hype, Web services are more exciting than car chases, are the answer to world peace, can cure male-pattern baldness, will patch the ozone layer, can resurrect failing economies, will make you rich and desirable, may bring an end to the glut of reality TV shows... well, you get the idea.

So, the big question has to be, are Web services for real? Microsoft thinks so (but not everything Microsoft believes in is truly worthy of consideration - anyone remember Microsoft Bob?). Sun (thanks to applets) thinks so too, as does IBM (those folks who brought us OS/2, which did so well). The point is, just because the big guys say it's hot does not necessarily make it so. And yet everyone is talking and writing about Web services (and I myself must plead guilty here - I have mentioned Web services in passing in several columns since ColdFusion MX shipped). So, again, what's the deal?

It's Distributed Applications - Again
For starters, here's an explanation. Web services are simply a set of technologies that facilitate distributed computing; it is that simple. The idea is that an application can invoke another application (located anywhere, locally or remotely) which does some processing, possibly returning results when complete. That's all there is to it.

It's not a new idea. Distributed computing has been around in some way, shape, or form for a while now (heck, if you use ColdFusion's <CFHTTP> tag to invoke a remote page, you are using distributed computing). So why the excitement this time around? There are a few reasons:

  • Vendor support: It's been a while since everyone from Microsoft to Sun to IBM to Apple all talked the same language (for the most part). Web services are truly the first really viable solution to interoperability.
  • Standards: Unlike other distributed computing technologies, Web services are built on existing standards and systems; no single vendor owns the space.
  • Cost: The two prior bullets make this technology highly usable and accessible, and not at all cost prohibitive. Most developers can continue to use the platforms and languages they already use and don't need to throw out everything and start over.

    Need a practical example? Try this one: you create an online store (I know that is so '90s, but bear with me). Customers visit your site and buy goods that you ship, using a carrier of your choice. Great. That is until a week goes by and no package shows up, so the customer revisits your site to track the order. You display the order information, complete with the shipper information and tracking number, allowing the customer to check on the delivery (and maybe, as you are so customer-service driven, you even provide a direct link to the shipper's site). Problem solved. Right?

    Wrong! If you have an online store, the last thing you want is customers wandering off to other sites; you want them to stay and part with their hard-earned money. You never want to send them off to or or any other site. doesn't do this - they show shipping information provided by those companies right in their own pages, the customer goes nowhere.

    I have no idea what systems the shipping companies use, I don't know what software they use, and I have no access to it anyway (I am guessing the same is true for you). is a very significant player in the e-commerce space, the shipping companies are likely to work with them to provide them with access to this kind of data. But what about the rest of us? How could we do the same?

    The answer is Web services (predictable, I know, sorry). If the shipping companies created a Web service that exposed tracking information, any application could submit a real-time request for the data, and then process or display it as needed right within their own pages. In other words, the client browser talks to your application; your application talks to the shipper via their Web service, retrieving the necessary information; and then your application displays it as needed.

    Fantasy? Well, that depends on who you ship your products with. But some shipping companies have indeed made Web services available. It's not fantasy at all.

    Web Services Lingo
    Okay, so now that you know why you need Web services, let's review some of the lingo you'll need to use (drop these in conversations to sound like a seasoned pro):

  • Web service: This is the application itself.
  • XML: Web service requests are made in XML and returned data is also in XML.
  • SOAP (Simple Object Access Protocol): The XML-based protocol used to send and receive Web service requests.
  • WSDL (Web Services Description Language): An XML language used to document Web services; every Web ser-vice has an associated WSDL URL which lists the methods (functions) that may be invoked as well as what parameters they expect and what data is returned.
  • UDDI (Universal Description, Discovery and Integration [of Web services]): A directory technology used to locate Web services (UDDI is not supported by ColdFusion in CFMX).

    When you use a Web service you consume it, and when you create a Web service you publish it.

    Consuming Web Services
    Enough talk, let's try this thing. In ColdFusion, Web services are consumed using the <CFINVOKE> tag. <CFINVOKE> requires the URL to a Web service's WSDL, the name of the method to invoke (a single Web service may expose multiple methods), and any required parameters.

    The following is a simple example. It invokes a Web service on my own Web site - this one returns my ColdFusion Tip-of-the-Day:

    <!--- Get tip for today --->

    As you can see, the Web service itself is specified using the URL to its WSDL file. ColdFusion retrieves and reads this file so as to know how to interact with the Web service, and how to call the method specified in the METHOD attribute. RETURNVARIABLE is the name of a ColdFusion variable to be populated with whatever results are returned. In this example my Web service returns a ColdFusion structure, and so DailyTip will be a structure containing the tip.

    If you want to try this example you can use <CFDUMP> to display the results, like this:

    <CFDUMP VAR="#DailyTip#">

    You'll notice that there is no XML here, no SOAP, nothing beyond a simple tag call. ColdFusion hides all the complexity from you - it does not matter what is on the other end, what language it was written in, what data type it returns, what platform it runs on - none of that matters. All that is important is that the returned data is ready to use just like any other ColdFusion variable.

    Here is another example, the same Web service call, but this time using a slightly different calling convention:

    <!--- Get tip for today --->

    As you can see, arguments may be specified as name=value pairs in <CFINVOKE>, or passed to nested <CFINVOKEARGUMENT> tags - the choice is yours, the end result is the same.

    Let's look at a complete example. Alta Vista has a translation engine named Babel Fish - pass it text and a destination language and it returns the translated text to you. The Babel Fish service requires two pieces of information, the text to be translated, and the translation mode (from what to what, for example en_de to translate English to German). See Listing 1 for a complete working application. It prompts for text and a destination language and displays the translation.

    As you can see, using Web services in ColdFusion is easy. I have no idea what the Babel Fish Web service is written in or what platform it runs on, nor do I care - the important thing is that I can invoke it and it just works. And that is the beauty of Web services.

    Note: Looking for a Web service to experiment with? Try

    If you are using Dreamweaver MX you'll find that Web services are even easier to use. In Dreamweaver, open the Application window, click on the Component tab, and then change the dropdown to Web services. Dreamweaver will list any known Web services (the list will be empty if this is the first time you are doing this). Click the + button and you'll be prompted for the WSDL URL of a Web service - simply enter it, and click OK. Dreamweaver MX will retrieve the WSDL, process and parse it, and will then display a tree of Web service methods and arguments. Then all you need to do is drag the desired method into your ColdFusion code, and Dreamweaver will create the <CFINVOKE> call for you automatically.

    Publishing Web Services
    Now that you know how to consume Web services, let's look at how to create and publish them. ColdFusion MX makes creating Web services incredibly easy - they are created as ColdFusion Comp-onents (explained in detail in CFDJ, Volume 4, issues 6, 7, and 10).

    Here is a simple ColdFusion Component. The file is named random.cfc, and it contains two methods: (1) Get returns a random number and (2) GetRange returns a random number within the specific range. (Okay, not the most glamorous examples, but they'll have to do). See Listing 2 for the code.

    The CFC code itself is rather simple. Get accepts no arguments and returns whatever is generated by Rand(); GetRange() accepts two required numeric arguments and passes them to RandRange() returning the results. This CFC can be used within your ColdFusion code using <CFINVOKE>, <CFOBJECT>, or CreateObject().

    So what makes this a Web service? The answer is the ACCESS level. Each of the <CFFUNCTION> tags has ACCESS="remote". Any ColdFusion Component methods with an ACCESS level of remote can be accessed remotely - as Web services; it's as simple as that.

    What about the WSDL file you need? ColdFusion does that too. The WSDL URL is the URL to the CFC with ?wsdl appended to it. I saved my random.cfc in my test directory, so the WSDL URL is http://localhost:8500/test/random.cfc?wsdl.

    Listing 3 is sample code showing this CFC being used as a Web service.

    Of course this particular CFC could be invoked as a CFC rather than as a Web service (and probably should be as it is ColdFusion and it is local). But with no extra work, the ColdFusion Component can also be used by:

    • Other ColdFusion servers
    • .NET
    • Java
    • PHP
    • Client-side Flash
    ColdFusion, and CFCs in particular, makes publishing Web services painless and even fun. You don't have to worry about XML, SOAP, data-type conversions - ColdFusion does all that for you. In fact, as I demonstrated at DevCon in Orlando, you'll find it easier to create Web services for Java and .NET in ColdFusion than in Java or any .NET language!

    Web services are all the rage right now. While the hype will die down a bit, all indications are that this is an important technology and one that will play an important role in application development now and in the foreseeable future. And best of all, as a ColdFusion developer, you have nothing to lose and lots to gain - it does not get much better than that.

  • More Stories By Ben Forta

    Ben Forta is Adobe's Senior Technical Evangelist. In that capacity he spends a considerable amount of time talking and writing about Adobe products (with an emphasis on ColdFusion and Flex), and providing feedback to help shape the future direction of the products. By the way, if you are not yet a ColdFusion user, you should be. It is an incredible product, and is truly deserving of all the praise it has been receiving. In a prior life he was a ColdFusion customer (he wrote one of the first large high visibility web sites using the product) and was so impressed he ended up working for the company that created it (Allaire). Ben is also the author of books on ColdFusion, SQL, Windows 2000, JSP, WAP, Regular Expressions, and more. Before joining Adobe (well, Allaire actually, and then Macromedia and Allaire merged, and then Adobe bought Macromedia) he helped found a company called which provides automotive services (buy a car, sell a car, etc) over the Web. (including Stoneage) is one of the largest automotive web sites out there, was written entirely in ColdFusion, and is now owned by Auto-By-Tel.

    Comments (3) View Comments

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

    Most Recent Comments
    Jon 10/02/06 03:13:39 PM EDT

    Thank you for taking the time to report on this topic. I have a question though.

    When you get errors using CFINVOKE to utilize web services and you're on a shared environment, how do you go about determining where the problem is? The error information is cryptic. The web service provider points to the programming or hosting, the host points to the service or programming and the programmer points to the host or web service provider! Of course, being the programmer, and having done several other CFINVOKE tags successfully, I am looking at the other two!

    So where to next?

    Could not generate stub objects for web service invocation. Name: WSDL: org.apache.axis.wsdl.toJava.DuplicateFileException: Duplicate file name: C:\CFusionMX7\stubs\WS1938286156\com\campaignmonitor\app\api\ Hint: you may have mapped two namespaces with elements of the same name to the same package name.

    Jon 10/02/06 03:12:48 PM EDT

    Thank you for taking the time to report on this topic. I have a question though.

    When you get errors using CFINVOKE to utilize web services and you're on a shared environment, how do you go about determining where the problem is? The error information is cryptic. The web service provider points to the programming or hosting, the host points to the service or programming and the programmer points to the host or web service provider! Of course, being the programmer, and having done several other CFINVOKE tags successfully, I am looking at the other two!

    So where to next?

    Could not generate stub objects for web service invocation. Name: WSDL: org.apache.axis.wsdl.toJava.DuplicateFileException: Duplicate file name: C:\CFusionMX7\stubs\WS1938286156\com\campaignmonitor\app\api\ Hint: you may have mapped two namespaces with elements of the same name to the same package name.

    jim kellow 01/16/03 08:25:00 AM EST

    Thanks for the time you spent on this.
    Like others, I have seen web services
    in articles but passed over it as I
    didn't have a clue what it was about.
    A couple of years ago, my company
    jumped into the web world with both
    feet and I rushed to create the site,
    but since then the interest has fallen
    to zero. I haven't been involved in the
    CF world for over a year now(we still
    use cf 4.5).
    I tried pushing for us to convert
    some of our existing application
    jobs to CF but it turned out that the
    conversion is about 10+ CF jobs to replace 1 application(oracle forms).
    I am trying to get us back into the
    CF world, but its gotten a lot bigger
    since we were there. I have a new
    copy of CF 5.0 on my desk but it is
    way out of date, so I am going to have
    to figure out which version of CF to
    suggest we move up to. Again, thanks
    for the article.


    @ThingsExpo Stories
    Container technology is shaping the future of DevOps and it’s also changing the way organizations think about application development. With the rise of mobile applications in the enterprise, businesses are abandoning year-long development cycles and embracing technologies that enable rapid development and continuous deployment of apps. In his session at DevOps Summit, Kurt Collins, Developer Evangelist at, examined how Docker has evolved into a highly effective tool for application delivery by allowing increasingly popular Mobile Backend-as-a-Service (mBaaS) platforms to quickly crea...
    Discussions of cloud computing have evolved in recent years from a focus on specific types of cloud, to a world of hybrid cloud, and to a world dominated by the APIs that make today's multi-cloud environments and hybrid clouds possible. In this Power Panel at 17th Cloud Expo, moderated by Conference Chair Roger Strukhoff, panelists addressed the importance of customers being able to use the specific technologies they need, through environments and ecosystems that expose their APIs to make true change and transformation possible.
    With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo 2016 in New York and Silicon Valley. Learn what is going on, contribute to the discussions, and ensure that your enterprise is as "IoT-Ready" as it can be! Internet of @ThingsExpo, taking place Nov 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 17th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound cha...
    Internet of @ThingsExpo, taking place June 7-9, 2016 at Javits Center, New York City and Nov 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with the 18th International @CloudExpo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world and ThingsExpo New York Call for Papers is now open.
    The cloud. Like a comic book superhero, there seems to be no problem it can’t fix or cost it can’t slash. Yet making the transition is not always easy and production environments are still largely on premise. Taking some practical and sensible steps to reduce risk can also help provide a basis for a successful cloud transition. A plethora of surveys from the likes of IDG and Gartner show that more than 70 percent of enterprises have deployed at least one or more cloud application or workload. Yet a closer inspection at the data reveals less than half of these cloud projects involve production...
    Growth hacking is common for startups to make unheard-of progress in building their business. Career Hacks can help Geek Girls and those who support them (yes, that's you too, Dad!) to excel in this typically male-dominated world. Get ready to learn the facts: Is there a bias against women in the tech / developer communities? Why are women 50% of the workforce, but hold only 24% of the STEM or IT positions? Some beginnings of what to do about it! In her Day 2 Keynote at 17th Cloud Expo, Sandy Carter, IBM General Manager Cloud Ecosystem and Developers, and a Social Business Evangelist, wil...
    Cloud computing delivers on-demand resources that provide businesses with flexibility and cost-savings. The challenge in moving workloads to the cloud has been the cost and complexity of ensuring the initial and ongoing security and regulatory (PCI, HIPAA, FFIEC) compliance across private and public clouds. Manual security compliance is slow, prone to human error, and represents over 50% of the cost of managing cloud applications. Determining how to automate cloud security compliance is critical to maintaining positive ROI. Raxak Protect is an automated security compliance SaaS platform and ma...
    In his keynote at @ThingsExpo, Chris Matthieu, Director of IoT Engineering at Citrix and co-founder and CTO of Octoblu, focused on building an IoT platform and company. He provided a behind-the-scenes look at Octoblu’s platform, business, and pivots along the way (including the Citrix acquisition of Octoblu).
    There are over 120 breakout sessions in all, with Keynotes, General Sessions, and Power Panels adding to three days of incredibly rich presentations and content. Join @ThingsExpo conference chair Roger Strukhoff (@IoT2040), June 7-9, 2016 in New York City, for three days of intense 'Internet of Things' discussion and focus, including Big Data's indespensable role in IoT, Smart Grids and Industrial Internet of Things, Wearables and Consumer IoT, as well as (new) IoT's use in Vertical Markets.
    Today air travel is a minefield of delays, hassles and customer disappointment. Airlines struggle to revitalize the experience. GE and M2Mi will demonstrate practical examples of how IoT solutions are helping airlines bring back personalization, reduce trip time and improve reliability. In their session at @ThingsExpo, Shyam Varan Nath, Principal Architect with GE, and Dr. Sarah Cooper, M2Mi’s VP Business Development and Engineering, explored the IoT cloud-based platform technologies driving this change including privacy controls, data transparency and integration of real time context with p...
    The Internet of Things (IoT) is growing rapidly by extending current technologies, products and networks. By 2020, Cisco estimates there will be 50 billion connected devices. Gartner has forecast revenues of over $300 billion, just to IoT suppliers. Now is the time to figure out how you’ll make money – not just create innovative products. With hundreds of new products and companies jumping into the IoT fray every month, there’s no shortage of innovation. Despite this, McKinsey/VisionMobile data shows "less than 10 percent of IoT developers are making enough to support a reasonably sized team....
    We all know that data growth is exploding and storage budgets are shrinking. Instead of showing you charts on about how much data there is, in his General Session at 17th Cloud Expo, Scott Cleland, Senior Director of Product Marketing at HGST, showed how to capture all of your data in one place. After you have your data under control, you can then analyze it in one place, saving time and resources.
    Just over a week ago I received a long and loud sustained applause for a presentation I delivered at this year’s Cloud Expo in Santa Clara. I was extremely pleased with the turnout and had some very good conversations with many of the attendees. Over the next few days I had many more meaningful conversations and was not only happy with the results but also learned a few new things. Here is everything I learned in those three days distilled into three short points.
    As organizations realize the scope of the Internet of Things, gaining key insights from Big Data, through the use of advanced analytics, becomes crucial. However, IoT also creates the need for petabyte scale storage of data from millions of devices. A new type of Storage is required which seamlessly integrates robust data analytics with massive scale. These storage systems will act as “smart systems” provide in-place analytics that speed discovery and enable businesses to quickly derive meaningful and actionable insights. In his session at @ThingsExpo, Paul Turner, Chief Marketing Officer at...
    DevOps is about increasing efficiency, but nothing is more inefficient than building the same application twice. However, this is a routine occurrence with enterprise applications that need both a rich desktop web interface and strong mobile support. With recent technological advances from Isomorphic Software and others, rich desktop and tuned mobile experiences can now be created with a single codebase – without compromising functionality, performance or usability. In his session at DevOps Summit, Charles Kendrick, CTO and Chief Architect at Isomorphic Software, demonstrated examples of com...
    In his General Session at 17th Cloud Expo, Bruce Swann, Senior Product Marketing Manager for Adobe Campaign, explored the key ingredients of cross-channel marketing in a digital world. Learn how the Adobe Marketing Cloud can help marketers embrace opportunities for personalized, relevant and real-time customer engagement across offline (direct mail, point of sale, call center) and digital (email, website, SMS, mobile apps, social networks, connected objects).
    The Internet of Everything is re-shaping technology trends–moving away from “request/response” architecture to an “always-on” Streaming Web where data is in constant motion and secure, reliable communication is an absolute necessity. As more and more THINGS go online, the challenges that developers will need to address will only increase exponentially. In his session at @ThingsExpo, Todd Greene, Founder & CEO of PubNub, exploreed the current state of IoT connectivity and review key trends and technology requirements that will drive the Internet of Things from hype to reality.
    Two weeks ago (November 3-5), I attended the Cloud Expo Silicon Valley as a speaker, where I presented on the security and privacy due diligence requirements for cloud solutions. Cloud security is a topical issue for every CIO, CISO, and technology buyer. Decision-makers are always looking for insights on how to mitigate the security risks of implementing and using cloud solutions. Based on the presentation topics covered at the conference, as well as the general discussions heard between sessions, I wanted to share some of my observations on emerging trends. As cyber security serves as a fou...
    Continuous processes around the development and deployment of applications are both impacted by -- and a benefit to -- the Internet of Things trend. To help better understand the relationship between DevOps and a plethora of new end-devices and data please welcome Gary Gruver, consultant, author and a former IT executive who has led many large-scale IT transformation projects, and John Jeremiah, Technology Evangelist at Hewlett Packard Enterprise (HPE), on Twitter at @j_jeremiah. The discussion is moderated by me, Dana Gardner, Principal Analyst at Interarbor Solutions.
    Too often with compelling new technologies market participants become overly enamored with that attractiveness of the technology and neglect underlying business drivers. This tendency, what some call the “newest shiny object syndrome” is understandable given that virtually all of us are heavily engaged in technology. But it is also mistaken. Without concrete business cases driving its deployment, IoT, like many other technologies before it, will fade into obscurity.