Adobe COLDFUSION 9 Manual page 1115

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
<cfcomponent>
<cffunction
name="allNames" returnType="name[]" access="remote" output="false">
<cfset var returnarray = ArrayNew(1)>
<cfset var temp = "">
<cfquery name="empinfo" datasource="cfdocexamples">
SELECT firstname, lastname
FROM employee
</cfquery>
<cfloop query="empinfo" >
<cfobject component="name" name="tempname">
<cfset tempname.Firstname = #empinfo.firstname#>
<cfset tempname.Lastname = #empinfo.lastname#>
<cfset temp = ArrayAppend(returnarray, tempname)>
</cfloop>
<cfreturn returnarray>
</cffunction>
</cfcomponent>
When you invoke the web service, it returns an array of CFCs. Access the properties in the CFC by using dot notation,
as the following example shows:
<cfinvoke webservice ="http://localhost:8500/ws/cfcarray.cfc?wsdl"
method ="allNames"
returnVariable="thearray">
<cfif IsArray(thearray)>
<h1>loop through the employees</h1>
<p>thearray has <cfoutput>#ArrayLen(thearray)#</cfoutput> elements.</p>
<cfloop index="i" from="1" to="#ArrayLen(thearray)#">
<cfoutput>#thearray[i].firstname#, #thearray[i].lastname# </cfoutput><br>
</cfloop>
<cfelse>
<h1>Error: thearray is not an array</h1>
</cfif>
Publishing document-literal style web services
In addition to RPC-oriented operations, for which consumers specify a method and arguments, ColdFusion also lets
you publish web services using the document-literal style. When you use document-literal style, the WSDL for the web
service tells the client to use XML schemas rather than RPC calling conventions.
In most cases, the publisher of a web services identifies it as document-literal or RPC style. To identify the type, open
the WSDL document and find the
shows:
<wsdl:binding name="WeatherForecastSoap" type="tns:WeatherForecastSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
In this example, the style is document-literal. Examine the WSDL to determine the methods you can call and the
parameters for each method.
On the client side, the
cfinvoke
automatically. In most cases, no modifications are necessary. Similarly, when publishing CFCs as document-literal
style web services, ColdFusion automatically creates and manages the appropriate WSDL.
element and examine its
soap:binding
tag and other ColdFusion methods for calling web services handle the style
Last updated 8/5/2010
attribute, as the following example
style
1110

Advertisement

Table of Contents
loading

Table of Contents