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 soap:binding
element and examine its style
attribute, as the following example 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. You must further examine the WSDL to determine the methods you can call and the parameters for each method.
On the client side, the cfinvoke
tag and other ColdFusion methods for calling web services handle this 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.
To publish CFCs as document-literal style web services, specify cfcomponent style="document"
, along with the other attributes required for document-literal style web services. For example, ColdFusion MX publishes the following CFC using document-literal style:
<cfcomponent style="document" > <cffunction name = "getEmp" returntype="string" output = "no" access = "remote"> <cfargument name="empid" required="yes" type="numeric"> <cfset var fullname = ""> <cfquery name="empinfo" datasource="cfdocexamples"> SELECT emp_id, firstname, lastname FROM employee WHERE emp_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.empid#"> </cfquery> <cfif empinfo.recordcount gt 0> <cfset fullname = empinfo.lastname & ", " & empinfo.firstname> <cfelse> <cfset fullname = "not found"> </cfif> <cfreturn #fullname#> </cffunction> </cfcomponent>
The cfcomponent
tag includes optional attributes that you can use to control the WSDL that ColdFusion generates. You can use these attributes to create meaningful WSDL attribute names, as the following example shows:
<cfcomponent style="document" namespace = "http://www.mycompany.com/" serviceportname = "RestrictedEmpInfo" porttypename = "RestrictedEmpInfo" bindingname = "myns:RestrictedEmpInfo" displayname = "RestrictedEmpInfo" hint = "RestrictedEmpInfo">
Tip: For complete control of the WSDL, advanced users can specify the cfcomponent
wsdlFile
attribute to use a predefined WSDL file.