Home / Articles / Adobe ColdFusion / Adobe ColdFusion 10 and SOAP-based Web Services

Adobe ColdFusion 10 and SOAP-based Web Services

Chapter Description

A web service is a web-based application or a network-accessible interface that can communicate and exchange data with other such applications over the Internet without regard for application, platform, syntax, or architecture. ColdFusion supports most of the messaging frameworks and protocols required to effectively communicate with different platforms, and web services are no exception.This chapter focuses primarily on using ColdFusion 10 with SOAP-based web services.

Application Settings

Four application-level web service settings can be used to apply certain properties related to web services across a given application. These settings are defined in Application.cfc in the this.wssettings struct, shown in Listing 4.12, which we will discuss one by one. Note that these application settings are introduced in ColdFusion 10 and are not available in previous ColdFusion versions.

Listing 4.12. /cfwack/4/Application.cfc


   <cfset this.name="cfwack_4">

   <cfset this.wssettings.version.publish = 2>
   <cfset this.wssettings.version.consume = 2>
   <cfset this.wssettings.style = "wrapped">
   <cfset this.wssettings.includeCFTypesInWSDL = false>


Including ColdFusion Types in WSDL

In our discussion of complex data types, we looked at the use of ColdFusion native data types with web services. These data types are similar to a number of data types in C++ and Java, but they do not exactly match any of the data types defined in the XML schema used by WSDL and SOAP for data-type representation and conversion.

This lack of a match is fine if a web service is published and consumed within ColdFusion because ColdFusion expects and understands its own data types and can serialize or deserialize them. However, when clients other than ColdFusion call this web service, they will need additional information to convert arguments to be sent with the web service call to data types that ColdFusion expects and understands.

Here is where this.wssettings.includeCFTypesInWSDL comes to our rescue. It tells ColdFusion whether to include ColdFusion’s native type information as an XML schema defined in the WSDL itself. Using this schema, other platforms can understand the arguments and result types.

If your web services will be used only with ColdFusion clients, there is no need to include this type information as it will increase the WSDL size. By default, it is set to false.

Deciding Which Web Service Engine to Use

Let’s step back a bit from our original topic of application settings. We said earlier that there are two web service engines available to us with ColdFusion 10. You can choose the web service engine to use according to your requirements:

  • Web Service Engine Version 1: Use this version if you want to publish WSDL in RPC style, or if you do not want all your existing web service clients to refresh their generated stubs. You should also use this version when you have web service clients on ColdFusion 9 and you use complex data types.
  • Web Service Engine Version 2: Use this version if you want to consume any web service that is based on WSDL 2.0, or if you want to publish WSDL in wrapped style. With ColdFusion 10, this is the default engine for publishing a web service.
  • Either engine: For all other scenarios, you can use either of the web service engines.

Specifying the Web Service Engine

ColdFusion uses Web Service Engine Version 2 by default to publish any component as a web service. However, you can override this behavior and tell ColdFusion which engine to use. You can specify the web service engine used to publish your ColdFusion components in any of three places:

  • Component level: You can specify wsversion with <cfcomponent> to declare the web service engine to use to publish that particular component. The possible values are 1 and 2. This setting takes the precedence over application- and server-level version declarations.
  • Application level: You can specify this.wssettings.version.publish in your Application.cfm file to declare the web service engine at the application level. All the components in the application will then be published using this setting. This setting takes precedence over the server-level setting.
  • Server level: You can specify the web service engine to be used across the server. Select the version on the Web Services page in the Data and Services section of ColdFusion Administrator, shown in Figure 4.4.
    Figure 4.4

    Figure 4.4. Changing the web service version in ColdFusion Administrator.

    While consuming a web service, ColdFusion will try to understand the WSDL style. If the style is Document Literal or Document Literal Wrapped, ColdFusion automatically uses Web Service Engine Version 2, and if the style is RPC Literal, ColdFusion automatically uses Web Service Engine Version 1. However, the caller can override this behavior by specifying the web service engine to be used while consuming web services. There are two places to provide this option:

  • While consuming a service: You can provide wsversion with <cfinvoke> to tell Cold-Fusion which web service engine to use to consume the web service. The possible values are 1 and 2, and this setting takes precedence over the application-level setting.
  • Application level: You can specify this.wssettings.version.consume in your Application.cfm file. Any call to consume web services will now use the specified version of the web service engine.

Choosing the WSDL Style

ColdFusion can publish WSDL and consume web services that publish WSDL in the following styles:

  • RPC Encoded: Specified with the <cfcomponent> attribute style="rpc", this style considers web services as XML-based forms of Remote Procedure Calls (RPCs). Here the SOAP message body contains only one element, which is named after the operation, and all parameters must be represented as subelements of this wrapper element. This style is available only with Web Service Engine Version 1.
  • Document Literal: Specified with the <cfcomponent> attribute style="document", this style considers web services as a means of moving XML information from one place to another. Here, the SOAP message body must follow the XML schema defined in WSDL as types. This style is available with both web service engine versions.
  • Document Literal Wrapped: Specified with the <cfcomponent> attribute style="wrapped", this style is similar to the Document Literal style, except that the SOAP message body is wrapped within a root element. This style is available only with Web Service Engine Version 2.

Alternatively, you can specify the WSDL style to use at the application level as this.wssettings.style. ColdFusion will use this information to generate WSDL in the specified style for all the CFCs in this application. You can individually override this setting with the <cfcomponent> attribute style, which takes precedence over application-level settings.

7. Configuring Web Services in ColdFusion Administrator | Next Section Previous Section