Workaround to Flex SDK 3.4 Bug 22333 :: HTTPService Responders Are Called Twice…Here’s a Fix!


This one kicked my team’s ass for a couple of hours so I’m hoping it’ll help somone else…so we updated our Flex SDKs to 3.4 and all of a sudden all of our Delegates’ result handlers were getting called twice. We thought it was due to our service orchestration object (we have a base object that allows us to make sequential Cairngorm service calls) and somehow we were calling the services 2x, but nope…wasn’t it. Seemed our AbstractDelegate that sets up the responders for all of our service calls like so had the issue:

public function executeHTTPService(requestDTO:AbstractRequestDTO=null):void
{
	logger.debug("executeHTTPService");

	var token:AsyncToken;
	var responder:mx.rpc.Responder;

	// create a responder for the service
	responder = new mx.rpc.Responder(result, fault); // WTF mate?

	// execute the service
	token = this.service.send(requestDTO);
	token.addResponder(responder); // why yall busted up now???
}

Apparently, SDK 3.4 reintroduces an old defect that causes this implementation of setting up the responder with the async token to call the result handler twice…bummer, eh? So what to do…well, a simple workaround until they fix this is to do the following:

this.service.addEventListener(ResultEvent.RESULT, result);
this.service.addEventListener(FaultEvent.FAULT, fault);

Just create your handlers with good-ole fashioned event handlers…DONE.

Get more info on the defect here.

Post to Twitter Tweet This Post

, , , , ,

  1. #1 by brianr - October 27th, 2009 at 17:27

    As a side note, make sure you remove your event listeners after the service has completed.

    And Flex SDK 3.4.1.10084 fixes this issue so you can go back to the token best practice (which takes care of the tear down and removal of event handlers, etc).

  2. #2 by Andrew Yahner - November 23rd, 2009 at 11:52

    I don’t like adding event listeners to services. What if your reuse your service and don’t want other listeners…

    better i think is this to attach a boolean to the TOKEN. check the boolean states before performing the work in your result handler.

    var token:AsyncToken=_service.send();
    token.executed=false;

    in the result handler, first statements should be:
    if (event.token.executed == false) {
    event.token.executed=true;
    //already fired (or firing);
    return;
    }

  3. #3 by Ruprict - February 27th, 2010 at 09:52

    You just saved me a ton of time….thanks..

(will not be published)
  1. No trackbacks yet.