Since I had developed such a pretty Web Service in Web Designer 2005 Express previously, I wanted to see the different methods to consume this service in various languages. I already demonstrated how to do so in ASP .Net, so now I have decided to go a little off the beaten path and do so in Coldfusion MX. Fortunately, doing so in Coldfusion MX using Dreamweaver as the development environment is incredibly easy.
In Dreamweaver 8, there is a really cool Web Service Component tool under the Application/Component tab. If you click on the “+” after selecting “Web Service” from the drop down, you will get a little wizard asking for the URL to retrieve the WSDL for the web service. That’s it; the Proxy generator will take care of the rest.
To consume the service, you can drag over the various methods into your Coldfusion page, or you can manually put in the Coldfusion tags to do so. In my case, I want to use the “getEmployeeAndTranscript” method in my web service, and return an Employee object. I need to pass in an ID as well, so I would use the CFINVOKE take like so:
<cfinvokeargument name="id" value="0005003335"/>
This will return my Employee object with the Transcript brought back as an array. Since the transcript is an array, I can loop through the results by retrieving the array length. Below is the code I used to return my results:
Total Courses: #ArrayLen(aEmployee.transcript.transcriptEntry)#<br />
<cfloop index="i" from="1" to="#ArrayLen(aEmployee.transcript.transcriptEntry)#">
The first thing I am doing in this snippet is returning the Employee information. Then I use the ArrayLen function to output the number of transcript entries. I then put a table in place and put up the header for the columns. I then use a CFLOOP tag to go through each element in the array. Coldfusion did something really strange with the Array itself. It created a Object called ArrayOfTranscript, with a property called transcriptEntry which contained the actual array. I suppose this is more inline with the original Web Service relationship I created. If I didn’t have the web service viewer that Dreamweaver provides, I would not have been able to determine this structure.