Packagenet.guttershark.support.servicemanager.http
Classpublic final class Service
InheritanceService Inheritance flash.utils.Proxy

The Service class is used to send http requests from the service manager. This class is used internally, and when using the service manager to make http calls, you are invariably using this class without realizing it. Don't use this class directly, use the service manager, this class is strictly for documentation.

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.


Example
Submitting data to a POST service.
 
  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{}
  

A file upload, with no upload data response:
 
  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.
  

A file upload, with file upload response data:
 
  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.
  



Public Methods
 MethodDefined 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
Constructor detail
Service()constructor
public function Service(url:String, attempts:int = 3, timeout:int = 1000, limiter:Boolean = false, defaultResponseFormat:String = "variables")

Constructor for Service instances.

Parameters
url: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")
Method detail
dispose()method
public function dispose():void

Dispose of this service.

send()method 
public function send(callProps:Object):void

Sends a service call, from parameters in the callProps object.

Parameters
callProps:Object — An Object with keys that control the service call, result handling, timeouts, etc.
toString()method 
public function toString():String

Friendly description.

Returns
String