In order for your flash application to communicate with the web service, you need to install the Flash remoting package from Macromedia. Also, it's very important that you place the flashgateway.dll file (included with Flash remoting for ASP.Net) into your web server's bin folder and make the below changes to your web.config file. These changes will allow Flash to determine what calls are meant for your flash application and call the proper web service. You'll also need to create a blank file named gateway.aspx and place it on your web server. I placed this file in the same location as my web service, but it's up to you.
<add name="GatewayController" type="FlashGateway.Controller.GatewayController,flashgateway" />
To establish the connection to our web service we must include the NetServices.as file. This file, included with Flash remoting, will implement the classes necessary to create a wrapper to our service.
Then we can create a connection to the web server gateway. In your code you will replace the //gateway.aspx and //YahooQuoteWebService.asmx?wsdl with the address of your web server and path to the gateway.aspx and YahooQuoteWebService.asmx files.
// Inits Web Service
//creates connection to ASP.Net web service
//should never ever run more than once!!
if( init == null )
//insures this code block is only run once
init = true;
//sets the gatway will always be this
gatewayConnnection = NetServices.createGatewayConnection();
//gets the Yahoo quote service and sets instance
//uses WSDL to create proxy dll file
YahooQuoteWebService = gatewayConnnection.getService("http:////YahooQuoteWebService.asmx?wsdl", this);
We need to develop call back functions and wrappers for our web service methods. When we call the GetQuote( string ) method on our web service, Flash will connect to the service and send the response back to _Result( result ) or _Status( error ). If a error occurs while trying to connect to the service, the _Status( error ) call back will be used, otherwise _Result( result ) will be called with the data from the service in the result object. Our result object is an array of strings so we can access this array like we would any Flash array object. NOTE: For a full list of result objects supported by Flash, see the Flash Remoting documentation.
// Call Back Function Wrappers
//gets quote data from web service
function GetQuote( symbol )
YahooQuoteWebService.GetQuote( symbol );
trace( "getting " + symbol + " from yahoo quote web service" );
// Call Back Functions
//call back function for GetQuote method
function GetQuote_Result( result )
buffer = result[ 0 ] + " " + result[ 1 ] + " " + result[ 4 ];
trace( buffer );
//call back function tracks status of GetQuote method
function GetQuote_Status( error )
trace( error.details );
After building our call back functions we can test our application by inserting the below lines of code at into our Action Script. This code will get the symbol, current value, and change data for Microsoft and display it in your trace window.
GetQuote( "MSFT" );