Table of contents:
- What's new
- Installing Remoting components
- Installing AMFPHP
- Testing AMFPHP
- 10,000 foot view of Remoting
- Creating Remoting methods
- Method table reference
- Helper classes
- NetDebug
- Authenticate
- DateWrapper
- Datatypes
- Class mapping
- Security
- Authentication
- Sending recordsets
- Manual recordsets
- Pageable recordsets
- Consuming web services (SOAP)
- Other platforms
- FAME
- Flex
- FlashCom
- The service browser
- Debugging
- Debugging primer
- NetConnection debugger
- Debugging proxies
- NetDebug::trace and exceptions
- Common confusing errors
- Deploying
- Credits
Consuming web services using AMFPHP
AMFPHP can consume web services using either of:
- SoapClient for PHP5
- NuSOAP
- PEAR::SOAP
In the first case you need the PHP5 SOAP extension installed on your web server. In the case of NuSOAP you will want to download NuSOAP and place the nusoap.php file in the flashservices/lib directory. In the case of PEAR::SOAP you need to have it installed in the usual PEAR include directory. If you have access to the PHP5 SOAP extension, you should use it as it is much faster than alternatives. Set the appropriate web service handler in the gateway.php file as indicated in the comments.
In Flash, to create a service you would use:
this.service = new Service(this.gatewayUrl, null, "PackageName.ServiceName", null, null);
And then you would call it using something along these lines:
var pc:PendingCall = this.service.myFunction(arg1, arg2); pc.responder = new RelayResponder(this, "handleMyFunction", "handleRemotingError");
All you need to change to consume web services is change the service name in the Service call. For example, to use Google’s API:
this.service = new Service(this.gatewayUrl, null, "http://api.google.com/GoogleSearch.wsdl", null, null);
To call this service, first store the required parameters in an array and call the function as though it were a Flash service:
var parameters = new Object(); parameters.key = "Za Google Key"; parameters.q = this.txtSearch.text; parameters.start = 0; parameters.maxResults = 10; parameters.filter = false; parameters.restrict = ''; parameters.safeSearch = false; parameters.lr = ''; parameters.ie = ''; parameters.oe = ''; var pc:PendingCall = this.service.doGoogleSearch(parameters); pc.responder = new RelayResponder(this, "handleGoogleSearch", "handleRemotingError");
And that’s about it. AMFPHP will automagically make the call to Google using your preferred SOAP handler and will forward it to you using AMF. Check you NetConnection Debugger for the exact output.
Note: return is a keyword in Flash. If your particular service has a property named return (like Google search API has) and you want to access it, writing object.return in actionscript will give an error on compile. Use object[’return’] (array syntax) to stop Flash’s compiler from whining.
Caveats
amfphp's web service handling is convenient, but be aware that it is slower than native services. In particular, if the web service is run on the php platform, it will often pay to convert it for Remoting (usually as simple as writing the method table); expect performance 70 to 90% faster with native services.
Common issues
For some web services (amazon's for example), you may have to wrap the parameters into a dummy array (the argument will then be available as $firstArg[0]['argName']). Others may require you to wrap your first argument in a dummy object with the 'arguments' or 'argument' key containing the actual data.
