0
votes

I am developing an AIR application with Flex Builder that requires me to make two HTTPService requests at the same time. They both use different instances of the HTTPService AS3 class. Both services are calling a RESTful API which is currently running on my localhost (XAMPP) and takes a few seconds to respond (much quicker on live server).

The problem is that most of the time one of the calls fails, however occasionally they do both work. Its also random as to which call will fail.

Thanks in advance,

Chris

Both calls use code something like this. This code is basically repeated in two classes.

//in constructor 
brokerageService = new HTTPService();
brokerageService.resultFormat = HTTPService.RESULT_FORMAT_E4X;
brokerageService.addEventListener(ResultEvent.RESULT, onBrokerageResult);
brokerageService.addEventListener(FaultEvent.FAULT, onFault); 
//call 
public function findBrokerages(type:String, value:String):void{
        var url:String = serviceURL + "Contacts/findBrokerage/" + type + "/" + value + ".xml";
        brokerageService.url = url;
        brokerageService.send();
} 
//response 
private function onBrokerageResult(e:ResultEvent):void{

        var response:XML = brokerageService.lastResult as XML;
        etc...
} 
// handle error 
private function onFault(e:FaultEvent):void{
        trace(e.target + " " + e.target.url);
        trace(e);
        dispatchEvent(new ServiceEvent(ServiceEvent.CONNECTION_PROBLEM, true));
}
3

3 Answers

0
votes

Can you paste the details of the error message you are getting? Are you sure this isn't a problem with the XMPP service? Try testing the service by sending the same requests with a tool like curl.

0
votes

I've resorted to resending the service request if a fault event occurs, up to a maximum of three times.

Its not my ideal solution but it works.

Chris

0
votes

I found myself getting these errors when I was getting malformed XML as a result, the E4X wouldn't/couldn't handle it. Try resending a failed request, and make the resultformat plain text, then check the output.