Welcome!

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 fedex.com or ups.com or any other site. Amazon.com 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). Amazon.com 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 --->
    <CFINVOKE WEBSERVICE="http://www.forta.com/cf/tips/syndicate.cfc?wsdl"
    METHOD="Get"
    DATE="#Now()#"
    RETURNVARIABLE="DailyTip">

    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 --->
    <CFINVOKE WEBSERVICE="http://www.forta.com/cf/tips/syndicate.cfc?wsdl"
    METHOD="Get"
    RETURNVARIABLE="DailyTip">
    <CFINVOKEARGUMENT NAME="date"
    VALUE="#Now()#"/>
    </CFINVOKE>

    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 www.xmethods.net.

    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!

    Conclusion
    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 Car.com which provides automotive services (buy a car, sell a car, etc) over the Web. Car.com (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: http://app.campaignmonitor.com/api/api.asmx?WSDL. WSDL: http://app.campaignmonitor.com/api/api.asmx?WSDL. org.apache.axis.wsdl.toJava.DuplicateFileException: Duplicate file name: C:\CFusionMX7\stubs\WS1938286156\com\campaignmonitor\app\api\SubscriberUnsubscribe.java. 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: http://app.campaignmonitor.com/api/api.asmx?WSDL. WSDL: http://app.campaignmonitor.com/api/api.asmx?WSDL. org.apache.axis.wsdl.toJava.DuplicateFileException: Duplicate file name: C:\CFusionMX7\stubs\WS1938286156\com\campaignmonitor\app\api\SubscriberUnsubscribe.java. 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.

    JimK

    @ThingsExpo Stories
    Software AG helps organizations transform into Digital Enterprises, so they can differentiate from competitors and better engage customers, partners and employees. Using the Software AG Suite, companies can close the gap between business and IT to create digital systems of differentiation that drive front-line agility. We offer four on-ramps to the Digital Enterprise: alignment through collaborative process analysis; transformation through portfolio management; agility through process automation and integration; and visibility through intelligent business operations and big data.
    There will be 50 billion Internet connected devices by 2020. Today, every manufacturer has a propriety protocol and an app. How do we securely integrate these "things" into our lives and businesses in a way that we can easily control and manage? Even better, how do we integrate these "things" so that they control and manage each other so our lives become more convenient or our businesses become more profitable and/or safe? We have heard that the best interface is no interface. In his session at Internet of @ThingsExpo, Chris Matthieu, Co-Founder & CTO at Octoblu, Inc., will discuss how these devices generate enough data to learn our behaviors and simplify/improve our lives. What if we could connect everything to everything? I'm not only talking about connecting things to things but also systems, cloud services, and people. Add in a little machine learning and artificial intelligence and now we have something interesting...
    Last week, while in San Francisco, I used the Uber app and service four times. All four experiences were great, although one of the drivers stopped for 30 seconds and then left as I was walking up to the car. He must have realized I was a blogger. None the less, the next car was just a minute away and I suffered no pain. In this article, my colleague, Ved Sen, Global Head, Advisory Services Social, Mobile and Sensors at Cognizant shares his experiences and insights.
    We are reaching the end of the beginning with WebRTC and real systems using this technology have begun to appear. One challenge that faces every WebRTC deployment (in some form or another) is identity management. For example, if you have an existing service – possibly built on a variety of different PaaS/SaaS offerings – and you want to add real-time communications you are faced with a challenge relating to user management, authentication, authorization, and validation. Service providers will want to use their existing identities, but these will have credentials already that are (hopefully) irreversibly encoded. In his session at Internet of @ThingsExpo, Peter Dunkley, Technical Director at Acision, will look at how this identity problem can be solved and discuss ways to use existing web identities for real-time communication.
    Can call centers hang up the phones for good? Intuitive Solutions did. WebRTC enabled this contact center provider to eliminate antiquated telephony and desktop phone infrastructure with a pure web-based solution, allowing them to expand beyond brick-and-mortar confines to a home-based agent model. It also ensured scalability and better service for customers, including MUY! Companies, one of the country's largest franchise restaurant companies with 232 Pizza Hut locations. This is one example of WebRTC adoption today, but the potential is limitless when powered by IoT. Attendees will learn real-world benefits of WebRTC and explore future possibilities, as WebRTC and IoT intersect to improve customer service.
    From telemedicine to smart cars, digital homes and industrial monitoring, the explosive growth of IoT has created exciting new business opportunities for real time calls and messaging. In his session at Internet of @ThingsExpo, Ivelin Ivanov, CEO and Co-Founder of Telestax, will share some of the new revenue sources that IoT created for Restcomm – the open source telephony platform from Telestax. Ivelin Ivanov is a technology entrepreneur who founded Mobicents, an Open Source VoIP Platform, to help create, deploy, and manage applications integrating voice, video and data. He is the co-founder of TeleStax, an Open Source Cloud Communications company that helps the shift from legacy IN/SS7 telco networks to IP-based cloud comms. An early investor in multiple start-ups, he still finds time to code for his companies and contribute to open source projects.
    The Internet of Things (IoT) promises to create new business models as significant as those that were inspired by the Internet and the smartphone 20 and 10 years ago. What business, social and practical implications will this phenomenon bring? That's the subject of "Monetizing the Internet of Things: Perspectives from the Front Lines," an e-book released today and available free of charge from Aria Systems, the leading innovator in recurring revenue management.
    The Internet of Things will put IT to its ultimate test by creating infinite new opportunities to digitize products and services, generate and analyze new data to improve customer satisfaction, and discover new ways to gain a competitive advantage across nearly every industry. In order to help corporate business units to capitalize on the rapidly evolving IoT opportunities, IT must stand up to a new set of challenges.
    There’s Big Data, then there’s really Big Data from the Internet of Things. IoT is evolving to include many data possibilities like new types of event, log and network data. The volumes are enormous, generating tens of billions of logs per day, which raise data challenges. Early IoT deployments are relying heavily on both the cloud and managed service providers to navigate these challenges. In her session at 6th Big Data Expo®, Hannah Smalltree, Director at Treasure Data, to discuss how IoT, Big Data and deployments are processing massive data volumes from wearables, utilities and other machines.
    All major researchers estimate there will be tens of billions devices – computers, smartphones, tablets, and sensors – connected to the Internet by 2020. This number will continue to grow at a rapid pace for the next several decades. With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo in Silicon Valley. Learn what is going on, contribute to the discussions, and ensure that your enterprise is as "IoT-Ready" as it can be!
    P2P RTC will impact the landscape of communications, shifting from traditional telephony style communications models to OTT (Over-The-Top) cloud assisted & PaaS (Platform as a Service) communication services. The P2P shift will impact many areas of our lives, from mobile communication, human interactive web services, RTC and telephony infrastructure, user federation, security and privacy implications, business costs, and scalability. In his session at Internet of @ThingsExpo, Erik Lagerway, Co-founder of Hookflash, will walk through the shifting landscape of traditional telephone and voice services to the modern P2P RTC era of OTT cloud assisted services.
    While great strides have been made relative to the video aspects of remote collaboration, audio technology has basically stagnated. Typically all audio is mixed to a single monaural stream and emanates from a single point, such as a speakerphone or a speaker associated with a video monitor. This leads to confusion and lack of understanding among participants especially regarding who is actually speaking. Spatial teleconferencing introduces the concept of acoustic spatial separation between conference participants in three dimensional space. This has been shown to significantly improve comprehension and conference efficiency.
    The Internet of Things is tied together with a thin strand that is known as time. Coincidentally, at the core of nearly all data analytics is a timestamp. When working with time series data there are a few core principles that everyone should consider, especially across datasets where time is the common boundary. In his session at Internet of @ThingsExpo, Jim Scott, Director of Enterprise Strategy & Architecture at MapR Technologies, will discuss single-value, geo-spatial, and log time series data. By focusing on enterprise applications and the data center, he will use OpenTSDB as an example to explain some of these concepts including when to use different storage models.
    SYS-CON Events announced today that Gridstore™, the leader in software-defined storage (SDS) purpose-built for Windows Servers and Hyper-V, will exhibit at SYS-CON's 15th International Cloud Expo®, which will take place on November 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Gridstore™ is the leader in software-defined storage purpose built for virtualization that is designed to accelerate applications in virtualized environments. Using its patented Server-Side Virtual Controller™ Technology (SVCT) to eliminate the I/O blender effect and accelerate applications Gridstore delivers vmOptimized™ Storage that self-optimizes to each application or VM across both virtual and physical environments. Leveraging a grid architecture, Gridstore delivers the first end-to-end storage QoS to ensure the most important App or VM performance is never compromised. The storage grid, that uses Gridstore’s performance optimized nodes or capacity optimized nodes, starts with as few a...
    The Transparent Cloud-computing Consortium (abbreviation: T-Cloud Consortium) will conduct research activities into changes in the computing model as a result of collaboration between "device" and "cloud" and the creation of new value and markets through organic data processing High speed and high quality networks, and dramatic improvements in computer processing capabilities, have greatly changed the nature of applications and made the storing and processing of data on the network commonplace. These technological reforms have not only changed computers and smartphones, but are also changing the data processing model for all information devices. In particular, in the area known as M2M (Machine-To-Machine), there are great expectations that information with a new type of value can be produced using a variety of devices and sensors saving/sharing data via the network and through large-scale cloud-type data processing. This consortium believes that attaching a huge number of devic...
    Innodisk is a service-driven provider of industrial embedded flash and DRAM storage products and technologies, with a focus on the enterprise, industrial, aerospace, and defense industries. Innodisk is dedicated to serving their customers and business partners. Quality is vitally important when it comes to industrial embedded flash and DRAM storage products. That’s why Innodisk manufactures all of their products in their own purpose-built memory production facility. In fact, they designed and built their production center to maximize manufacturing efficiency and guarantee the highest quality of our products.
    Can call centers hang up the phones for good? Intuitive Solutions did. WebRTC enabled this contact center provider to eliminate antiquated telephony and desktop phone infrastructure with a pure web-based solution, allowing them to expand beyond brick-and-mortar confines to a home-based agent model. Download Slide Deck: ▸ Here
    All major researchers estimate there will be tens of billions devices - computers, smartphones, tablets, and sensors - connected to the Internet by 2020. This number will continue to grow at a rapid pace for the next several decades. Over the summer Gartner released its much anticipated annual Hype Cycle report and the big news is that Internet of Things has now replaced Big Data as the most hyped technology. Indeed, we're hearing more and more about this fascinating new technological paradigm. Every other IT news item seems to be about IoT and its implications on the future of digital business.
    BSQUARE is a global leader of embedded software solutions. We enable smart connected systems at the device level and beyond that millions use every day and provide actionable data solutions for the growing Internet of Things (IoT) market. We empower our world-class customers with our products, services and solutions to achieve innovation and success. For more information, visit www.bsquare.com.
    With the iCloud scandal seemingly in its past, Apple announced new iPhones, updates to iPad and MacBook as well as news on OSX Yosemite. Although consumers will have to wait to get their hands on some of that new stuff, what they can get is the latest release of iOS 8 that Apple made available for most in-market iPhones and iPads. Originally announced at WWDC (Apple’s annual developers conference) in June, iOS 8 seems to spearhead Apple’s newfound focus upon greater integration of their products into everyday tasks, cross-platform mobility and self-monitoring. Before you update your device, here is a look at some of the new features and things you may want to consider from a mobile security perspective.