Using WebServices in FMS

This one is a quick beginner tutorial on using WebServices in Flash Media Server. Here you will learn how to retrieve web-service data from server side and pass it to all users connected to application. As an example I’m going to retrieve weather forecast.

// Load WebService component.
load("webservices/WebServices.asc");
 
application.onAppStart = function()
{
	trace ("Application Started");
	// Load WebService.
	this.loadWS();
}
 
application.onConnect = function(client)
{
	// Handle client functionality...
	application.acceptConnection(client);
}
 
application.loadWS = function()
{
	// Define WebService.
	weatherService = new WebService("http://www.webservicex.net/WeatherForecast.asmx?WSDL");
 
	weatherService.onLoad = function()
	{
		trace ("weatherService loaded...");
		// Invoke getWeatherByName method and set interval
		// to invoke it every 10 seconds for example.
		application.getWeatherByName("New York");
		setInterval(application.getWeatherByName, 10000, "New York");
	}
 
	weatherService.onFault = function(fault)
	{
		// Handle error here.
		trace (fault.faultstring);
	}
}
 
application.getWeatherByName = function(location)
{
	// Invoke web-service method passing it the location.
	weatherByName = weatherService.GetWeatherByPlaceName(location);
 
	weatherByName.onResult = function(result)
	{		
		var newObj = new Array();
 
		// Loop throught result and push needed fields to array.
		for ( var i = 0; i < result.Details.length; i++ )
		{
			newObj.push({day:result.Details[i].Day, min:result.Details[i].MinTemperatureC, max:result.Details[i].MaxTemperatureC});
		}
 
		var c = application.clients;
 
		if ( c.length )
		{
			// Loop throught clients and pass weather data.
			for ( var j = 0; j < c.length; j++ )
			{
				c[j].call("setWeather", null, newObj);
			}
		}
 
	}
 
	weatherByName.onFault = function(fault)
	{
		// Handle error here.
		trace(fault.faultstring);
	}
}

Everything should be clear if you have Read more