Basic Walk Through of Consuming a web service
For this example we will be using the Nusoap/Soapx4 Toolkit, you will need to download this file from
http://dietrich.ganx4.com/nusoap/
or
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/nusoap/lib/.
You only need the nusoap.php file. The other files are not needed, however you may find them useful later on.
Set up the Script:
Below is a sample script for consuming the Babelfish web service. The basic parts to the script will be the same for other toolkits, the syntax will be slightly different though.
// Include the nusoap.php file we downloaded a bit earlier.
// Place this in the same directory as this script.
require_once('nusoap.php');
// Add necessary Parameters. In this case Translation mode indicates
// which language you want to translate to and from. Source data is the
// text you want to translate.
$parameters = array(
"translationmode"=>"en_fr",
"sourcedata" =>"Hello World - this is french"
);
// Create a new Soap object
$soapclient = new soapclient('http://www.xmethods.net/sd/2001/BabelFishService.wsdl','wsdl');
// Call the service - the method to call is shown in red.
$result = $soapclient->call('BabelFish',$parameters);
// Print the result.
print "$result";
Try it:Place the above script and nusoap.php in the same directory, then call the above script from a browser. The translation of 'Hello Worl...' from english to french should be displayed. This is a good way to test everything out the first time.
Basic Parts:
On the first line we include the nusoap.php file, this file does all of the actual work for us.
Define Parameters:
Next we define the parameters we send to the service. You can find the needed parameters for any service with the WSDL inspector in the Web Service directory (Input area).
Create new soap Client:
After we have defined are parameters we set up a new soap client. We need to specify the path to the WSDL file (Shown in Green) nusoap will then parse the WSDL file for us and find the endpoint of the service and all of the other needed details.
Call the Service:
After we have gathered all of the necessary information on the service we call the service. A service's can have muliple operations, so we need to specify which one to invoke. In this case it's the BabelFish operation/method. We also pass the service the parameters we defined earlier in this step.
Print out the result:
Last, but not least we print out what was returned from the service. This is usually a string or an array. If it's an array we usually need to add a line or two to pick out the parts of the returned array that are useful. Then format the result so that flash can read it back in.
And that's it:
We will try to put together some more in-depth examples in the near future.

5 most recent
Tree menu
Flex form by email
Flash Spell Checker
Flash Remoting Library
MX 2004 Chart/Poll
Articles