开发者

Multiple HTTPService Requests with Flex and AIR

开发者 https://www.devze.com 2022-12-11 12:03 出处:网络
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 a

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 li开发者_JAVA百科ke 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));
}


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消