View comments | RSS feed

Calling web services from Flash

Using the Flash Remoting web service adapter, you can call web services from Flash that are described by the Web Services Description Language (WSDL). You must first generate a local web service proxy to interact with web services. After you create the proxy, the ActionScript in your Flash application can then invoke web service methods through the proxy, which handles sending and receiving Simple Object Access Protocol (SOAP) messages with the remote web service.

In .NET, you can generate proxy assemblies with the WSDL Tool (wsdl.exe). Flash Remoting MX for .NET also uses the WSDL Tool to generate SOAP proxies for web services automatically from valid WSDL, either local or remote. In addition, Flash Remoting MX does not restrict you to .NET-based web services. Rather, any WSDL-described web service is available to Flash Remoting MX.

If you want to invoke web services using a .NET web service proxy assembly of your own that contains the web service definition, place the DLL file into the local assembly cache of your ASP.NET application. The proxy DLL must have the exact same name as the web service name, as described by the WSDL's service element. To invoke the web service proxy from ActionScript, supply the web service's fully qualified WSDL URL as the service address argument of the gatewayConnection.getService function, and use the web service's method names as the service function names.

Invoking web service methods using Flash Remoting MX

Flash Remoting MX uses the .NET WSDL Tool to generate the necessary proxy classes automatically by specifying a valid URL to a WSDL file or to a URL that can generate a WSDL file, such as a .NET ASMX file. To invoke a local web service in an ASMX file from Flash, you enter the URL to the file appended with ?wsdl, as the following ActionScript example shows:

NetServices.setDefaultGatewayUrl("http://localhost/myASPApp/default.aspx");
gatewayConnection = NetServices.createGatewayConnection();
flashService = gatewayConnnection.getService("http://localhost/myASPApp/ExampleWebService.asmx?wsdl", this);

In the getService function, you use the URL to the WSDL file, or a file capable of generating WSDL, as the service name. In the ASMX file, a getMessage method has been defined, as the following C# example shows:

[WebMethod]
public string getMessage()
{
  return "Flash Remoting makes web services easy!";
}

To call this method in ActionScript, you use the method name in the context of the flashService connection object, as the following ActionScript example shows:

flashService.GetMessage();

To display the results of the method invocation in Flash, you use an event handler, as the following example shows:

function getMessage_Result(result)
{
  serviceMessage.text = result;
}
function getMessage_Status(result)
{
  serviceMessage.text = error.description;
}

In the code, the results of the getMessage web service method call are displayed in the serviceMessage dynamic text field. For more information on handling results, see Chapter 2, "Handling service results".

Invoking a remote web service from Flash

Using Flash Remoting MX for .NET, you can invoke any remote .NET-compatible web service directly from your Flash application with no .NET application development required. To find a remote web service, go to a public Universal Description, Discovery, and Integration (UDDI) registry, such as http://www.xmethods.net. Using the WSDL URL and method names found in the registry, you write ActionScript in your Flash application to invoke the web service.

To interact with remote web services, just like local web services, Flash Remoting MX uses the .NET framework's WSDL Tool (wsdl.exe) to create web service proxies dynamically in the form of assemblies (*.dll). Remember, you must allow write and modify permissions for your ASP.NET application's local assembly cache.

For example, the following ActionScript code connects to a Temperature web service (http://www.xmethods.net/sd/2001/TemperatureService.wsdl), which returns the local temperature by U.S. zip code:

#include "NetServices.as"
if (inited == null)
{
  inited = true;
  NetServices.setDefaultGatewayUrl("http://localhost/myASPApp/default.aspx");
  gatewayConnection = NetServices.createGatewayConnection();
  webService = gatewayConnnection.getService("http://www.xmethods.net/sd/2001/TemperatureService.wsdl", this);
  webService.getTemp(zip.text);
}
function getTemp_Result(result) 
{                
  tempDisplay.text = result;
} 
function getTemp_Status(result) 
{                
  tempDisplay.text = error.description;
} 

In the ActionScript code, you replace the directory structure of the getService function argument with a URL that produces WSDL. The getTemp function maps to the web service method of the same name. The code assumes that zip represents an input text field, and tempDisplay represents a dynamic text field.

To see the web service proxy assembly (*.dll) that Flash Remoting MX creates, look in your local assembly cache for a DLL with the same name as the web service. For the Temperature web service, look for a DLL named TemperatureService.dll.

Comments


ricardo_cambio said on Sep 9, 2003 at 12:25 PM :
I'm having trouble with the receiving some responses from the server.
Is there a size or request time limitation?
If so, can it be modified?
No screen name said on Feb 1, 2005 at 8:41 PM :
i created proxy in .net side and called a method but still method is not invoking

--A
No screen name said on Jul 2, 2005 at 2:28 PM :
About : Invoking a remote web service from Flash

I copied the mentioned code.
Created a folder flremoting under webroot. Made it as an application in IIS. Copied gateway.aspx. Created a bin folder.

Changed the gateway to http://localhost/flremoting/gateway.aspx

But I get no response.

Which user needs write permissions to the BIN directory. Does wsdl.exe have to be in the PATH ?

Thanks

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flashremoting/mx/Using_Flash_Remoting_MX/usingFRNET5.htm