10.3 Web Services from a ColdFusion Server

When the server environment for web services is ColdFusion MX, you don't have to do anything on the server side to consume a web service. The Flash movie merely has to reference the Flash Remoting adapter on the server. The ColdFusion MX Server contains the necessary SOAP translation requirements and creates a proxy for the web service. The Flash Remoting gateway translates the SOAP reply from the proxy into the ActionScript objects that Flash will understand.

As of ColdFusion Updater 3, web services are not enabled by default in ColdFusion MX. This is for security reason; a malicious user can hijack a Flash Remoting gateway to call web services. To enable the web services, the web.xml file in the ColdFusion MX installation needs to be changed. Read the Updater 3 release notes at http://www.macromedia.com/support/coldfusion/releasenotes/mx/releasenotes_mx_updater01.html for more information.

ColdFusion MX creates Java stub classes as a proxy for the web service behind the scenes. These proxy classes are located in ColdFusion_MX_root\stubs. Upon first calling the web service, the proxy is created. It remains in place for subsequent calls. For that reason, the first call to the service will take more time. The same is true for a web service called through Flash Remoting using ASP.NET.

To demonstrate a simple example, we'll call the Whois web service at http://www.soapclient.com/xml/SQLDataSoap.wsdl. Services such as these can be found at http://www.xmethods.com and other UDDI registries.

The availability of a particular web service comes and goes, but the code shown in Example 10-1 should work for any similar Whois service, including the one at http://www.flash-remoting.com/whois.wsdl, which takes one simple argument: domain.

Example 10-1 shows the client-side ActionScript code necessary to call a remote web service. The Flash movie also contains a text field named domain_txt to get the user input, a text field named results_txt to hold the results, and a button named submit_pb to call the service. Notice that the service name is a fully qualified URL of the .wsdl file for the web service. The ColdFusion MX Server creates a proxy for the service. Again, the myURL variable in the sample code contains the reference to a local ColdFusion Server at port 8500, but you should change this URL to your own Flash Remoting location.

Example 10-1. Client-side ActionScript code for accessing a Whois service
#include "NetServices.as"

// Set up variables for the URL and service paths
var myURL = "http://localhost:8500/flashservices/gateway";
var servicePath = "http://www.soapclient.com/xml/SQLDataSoap.wsdl";

// Define the custom class SimpleResult
function SimpleResult( ) {
// Set up onResult and onStatus handlers as methods of the SimpleResult class
SimpleResult.prototype.onResult = function (myResults) {
  results_txt.text = myResults;
SimpleResult.prototype.onStatus = function (myError) {
  results_txt.text = myError.description;
// Set the system status to be handled by the result status handler as well
System.onStatus = SimpleResult.prototype.onStatus;

// Connection hasn't been initialized; create connection and service objects
if (initialized == null) {
  initialized = true;
  var myConnection_conn = NetServices.createGatewayConnection( );
  var myService = myConnection_conn.getService(servicePath, new SimpleResult( ));

// Call the service when the user clicks the Submit button
function getWhois ( ) {

Upon running the movie, you are prompted for a domain name. You can enter a domain name and click Submit. The web service responds with the Whois data for that particular domain.

    Part III: Advanced Flash Remoting