In addition to supporting the consumption of Web Services, ColdFusion also allows developers to create their own Web Services for consumption by ColdFusion, .NET, Java, and more. Web Services are created using ColdFusion Components.
ColdFusion Components were reviewed in Chapter 31, "ColdFusion Components." ColdFusion Components are automatically ready to be used as Web Services, but for security reasons code is not accessible as a Web Service unless specifically enabled. To make a CFC method accessible as a Web Service, simply set access="remote", as seen here: <!--- User component ---> <cfcomponent> <!--- List users method ---> <cffunction name="List" access="remote" returntype="query"> <!--- Get users ---> <cfquery name="users" datasource="exampleapps"> SELECT EmployeeID AS UserID, FirstName, LastName FROM tblEmployees ORDER BY LastName, FirstName </cfquery> <cfreturn users> </cffunction> </cfcomponent> The List method in this component returns a query (obtained by using a <cfquery> tag), and because access="remote", the method will be accessible as a Web Service. NOTE The <cffunction> returntype attribute is optional in ColdFusion Components, but it is required if the method is used as a Web Service. ColdFusion also automatically generates the required WSDL on demand. The WSDL URL for any ColdFusion Component is the URL to the CFC appended with ?wsdl. For example, the WSDL for the ColdFusion Tip-of-the-Day Web Service at www.forta.com is: http://www.forta.com/cf/tips/syndicate.cfc?wsdl TIP ColdFusion Components can be invoked as CFCs or as Web Services, but for performance reasons, CFC invocation is preferred. Working With SOAP HeadersWithin CFCs, the following functions may be used to access SOAP headers (that is, headers within a received request):
|