| Package | net.guttershark.support.servicemanager.http |
| Class | public final class Service |
| Inheritance | Service flash.utils.Proxy |
When you make a service call from the service manager, and pass it an object of properties, you are passing it a "callProps" object.
Supported properties on the callProps object:
Extended file upload info. If you're upload service returns some data, that data will be passed to your onResult in a CallResult instance. If no data is returned from the server, a call result object will not be passed to your onResult, or onFault callbacks.
File upload responses.
If you do not send back a response,
the flash client does not fire the complete event. This is problamatic, so make
sure to send at least a variable response like: result=true, this
ensures that the on result handlers will correctly fire.
HTTP Service calls support a couple extra features, and, if you follow the rules with the responses from the server, you can trigger the onFault callback. This is useful for situations where the server may have returned a 200 OK, but you need to indicate to the client that it was a faulty operation.
For "xml" responses
A successful xml response can be any well formed xml, which will trigger the onResult callback.
To indicate a fault, and call the onFault callback, send an XML structure like this as the response:
<root>
<fault>my message</fault>
</root>
Note: the root node name doesn't matter in this case, it's the fault node that matters
For "variable" responses
The response should be a url encoded string like so: (name=asdfasd&email=asdfasd&test=sdfsdf)
To indicate a fault through variables define it like so: (fault=my%20fault%20message).
For text or binary response formats, no translation of the response occurs, it's handed back to you as raw data in either the call result, or call fault.
import net.guttershark.managers.ServiceManager;
import net.guttershark.support.serviceamanager.shared.CallResult;
import net.guttershark.support.serviceamanager.shared.CallFault;
var sm:ServiceManager = ServiceManager.gi();
sm.createHTTPService("sendEmail","http://localhost/sendEmail.php",3,5000,false);
sm.sendEmail({method:"post",responseFormat:"variables",data:{toEmail:"test@example.com",subject:"Example",message:"Hello World"},onResult:onr,onFault:onf});
function onr(cr:CallResult):void{}
function onf(cf:CallFault):void{}
import net.guttershark.managers.ServiceManager;
var sm:ServiceManager = ServiceManager.gi();
sm.createHTTPService("uploadFile","http://localhost/uploadFile.php");
sm.uploadFile({file:myFileReference,onResult:onr,onFault:onf});
function onr():void{} //no parameter here, as no result data is received.
function onf():void{} //no parameter here, as no result data is received.
import net.guttershark.managers.ServiceManager;
import net.guttershark.support.serviceamanager.shared.CallResult;
import net.guttershark.support.serviceamanager.shared.CallFault;
var sm:ServiceManager = ServiceManager.gi();
sm.createHTTPService("uploadFile","http://localhost/uploadFile.php");
sm.uploadFile({file:myFileReference,onResult:onr,onFault:onf});
function onr(cr:CallResult):void{} //no parameter here, as no result data is received.
function onf(cf:CallFault):void{} //no parameter here, as no result data is received.
| Method | Defined by | ||
|---|---|---|---|
|
Service(url:String, attempts:int = 3, timeout:int = 1000, limiter:Boolean = false, defaultResponseFormat:String = "variables")
Constructor for Service instances.
| Service | ||
|
dispose():void
Dispose of this service.
| Service | ||
|
send(callProps:Object):void
Sends a service call, from parameters in the callProps object.
| Service | ||
|
toString():String
Friendly description.
| Service | ||
| Service | () | constructor |
public function Service(url:String, attempts:int = 3, timeout:int = 1000, limiter:Boolean = false, defaultResponseFormat:String = "variables")Constructor for Service instances.
Parametersurl:String — The id of this service.
|
|
attempts:int (default = 3) — The endpoing URL.
|
|
timeout:int (default = 1000) — The HTTP method. GET/POST.
|
|
limiter:Boolean (default = false) — The default responses data format.
|
|
defaultResponseFormat:String (default = "variables") |
| dispose | () | method |
public function dispose():voidDispose of this service.
| send | () | method |
public function send(callProps:Object):voidSends a service call, from parameters in the callProps object.
ParameterscallProps:Object — An Object with keys that control the service call, result handling, timeouts, etc.
|
| toString | () | method |
public function toString():StringFriendly description.
ReturnsString |