DekGenius.com
[ Team LiB ] Previous Section Next Section

Recipe 20.24 Consuming Web Services with Flash Remoting for .NET or ColdFusion

20.24.1 Problem

You want to consume a web service using Flash Remoting for .NET or ColdFusion.

20.24.2 Solution

Use a Flash Remoting service object that maps to the .wsdl file for the web service and invoke the web service method from the service object.

20.24.3 Discussion

One of the great features of Flash Remoting for .NET and ColdFusion is that you can use it to invoke web service methods directly from the Flash movie. You don't have to create any server-side scripts to consume the web service and return the results to Flash.

The process for calling a web service method from a Flash movie is the same as calling any service function using Flash Remoting. You need to create a connection object, a service object, and a response object. Then, you only need to invoke the service function from the service object and tell it to return the results to the response object. The only change when working with web services (versus service functions) is that you should map the service object to the web service's WSDL (Web Services Description Language) document. You should still use your local application server as the Flash Remoting gateway, regardless of the domain of the web service. Your local application server actually proxies the request for you. For example:

// Create a connection object that uses your local application server 
// as the Flash Remoting gateway.
gwURL = "http://localhost:8500/flashservices/gateway";
NetServices.setDefaultGatewayUrl(gwURL);
myConnection = NetServices.createGatewayConnection(  );

// Create a service object that maps to the WSDL document for the web service. In
// this example it exists at http://www.somedomain.com/wsdls/myWebService.wsdl.
wsSrv = myConnection.getService(
    "http://www.somedomain.com/wsdls/myWebService.wsdl");

// Create a response object.
myResponse = new Object(  );
myResponse.onResult = function (result) {
  // Do something with the result here.
};

// Invoke a web service method named myWebMethod(  ).
wsSrv.myWebMethod(myResponse);

20.24.4 See Also

See Recipe 20.2 and Recipe 20.3 for important configuration information to allow Flash Remoting access to web services with ColdFusion MX Updater 3 and ASP.NET. For more information, see http://www.flash-remoting.com/notablog/home.cfm?newsid=21.

    [ Team LiB ] Previous Section Next Section