FredMBarrett
asked on
ResultEvents not firing on multiple Flex3 WebService calls
I have a user form in Flex that has three drop-downs that need to be initialized. I have created a class that wraps the web service methods:
public function GetShipments( custId:int ):void {
ws.addEventListener( ResultEvent.RESULT, WebService_Results );
var callToken:AsyncToken = ws.getShipmentsForCustomer ( custId );
callToken.marker = "shipments";
}
public function GetRoutes( custId:int ):void {
ws.addEventListener( ResultEvent.RESULT, WebService_Results );
var callToken:AsyncToken = ws.getRoutesForCustomer( custId );
callToken.marker = "routes";
}
public function GetDevices( custId:int ):void {
ws.addEventListener( ResultEvent.RESULT, WebService_Results );
var callToken:AsyncToken = ws.getDevicesForCustomer( custId );
callToken.marker = "devices";
}
private function WebService_Results( e:ResultEvent ):void {
var results:ArrayCollection;
switch ( e.token.marker ) {
case "shipments":
trace( "got shipment results" );
results = Route.ArrayToTypedArray( e.result as ArrayCollection );
dispatchEvent( new ShipmentsEvent( ShipmentsEvent.LOAD, results ) );
break;
case "routes":
trace( "got route results" );
results = Route.ArrayToTypedArray( e.result as ArrayCollection );
dispatchEvent( new RoutesEvent( RoutesEvent.LOAD, results ) );
break;
case "devices":
trace( "got device results" );
results = Device.ArrayToTypedArray( e.result as ArrayCollection );
dispatchEvent( new DeviceEvent( DeviceEvent.LOAD, results ) );
break;
}
}
On my user form, I call the init() function on creationComplete:
private function init():void {
mySvc.getInstance().addEve ntListener ( ShipmentsEvent.LOAD, GetShipments_Result );
mySvc.getInstance().addEve ntListener ( RoutesEvent.LOAD, GetRoutes_Result );
mySvc.getInstance().addEve ntListener ( DeviceEvent.LOAD, GetDevices_Result );
mySvc.getInstance().getShi pments( 2 );
mySvc.getInstance().getRou tes( 2 );
mySvc.getInstance().getDev ices( 2 );
}
In Service Capture, as expected I see 4 requests to the web service and the correct results returned:
GET WSDL
getShipments
getRoutes
getDevices
However, only one trace gets fired...
"got shipment results"
If I sequence them by calling getRoutes in the result handler of getShipments, and getDevices in the result handler of getRoutes, all three events are received fine.
However, this seems horribly clumsy and hard to manage over a large enterprise application.
What might I be doing wrong, or is sequencing the only way to go?
public function GetShipments( custId:int ):void {
ws.addEventListener( ResultEvent.RESULT, WebService_Results );
var callToken:AsyncToken = ws.getShipmentsForCustomer
callToken.marker = "shipments";
}
public function GetRoutes( custId:int ):void {
ws.addEventListener( ResultEvent.RESULT, WebService_Results );
var callToken:AsyncToken = ws.getRoutesForCustomer( custId );
callToken.marker = "routes";
}
public function GetDevices( custId:int ):void {
ws.addEventListener( ResultEvent.RESULT, WebService_Results );
var callToken:AsyncToken = ws.getDevicesForCustomer( custId );
callToken.marker = "devices";
}
private function WebService_Results( e:ResultEvent ):void {
var results:ArrayCollection;
switch ( e.token.marker ) {
case "shipments":
trace( "got shipment results" );
results = Route.ArrayToTypedArray( e.result as ArrayCollection );
dispatchEvent( new ShipmentsEvent( ShipmentsEvent.LOAD, results ) );
break;
case "routes":
trace( "got route results" );
results = Route.ArrayToTypedArray( e.result as ArrayCollection );
dispatchEvent( new RoutesEvent( RoutesEvent.LOAD, results ) );
break;
case "devices":
trace( "got device results" );
results = Device.ArrayToTypedArray( e.result as ArrayCollection );
dispatchEvent( new DeviceEvent( DeviceEvent.LOAD, results ) );
break;
}
}
On my user form, I call the init() function on creationComplete:
private function init():void {
mySvc.getInstance().addEve
mySvc.getInstance().addEve
mySvc.getInstance().addEve
mySvc.getInstance().getShi
mySvc.getInstance().getRou
mySvc.getInstance().getDev
}
In Service Capture, as expected I see 4 requests to the web service and the correct results returned:
GET WSDL
getShipments
getRoutes
getDevices
However, only one trace gets fired...
"got shipment results"
If I sequence them by calling getRoutes in the result handler of getShipments, and getDevices in the result handler of getRoutes, all three events are received fine.
However, this seems horribly clumsy and hard to manage over a large enterprise application.
What might I be doing wrong, or is sequencing the only way to go?
ASKER
Hi ChristoferDutz:
Thanks for your reply. I made the updates you suggested and still no love. The traces all show that, basically whichever event happens first, that one wins and all others are lost.
I moved the token definitions outside of the function and created a token for each method call.
I also added the event listener to the token itself.
public function GetShipments( custId:int ):void {
ws.addEventListener( ResultEvent.RESULT, WebService_Results );
_getShipmentsToken = ws.getShipmentsForCustomer ( custId );
_getShipmentsToken.addEven tListener( ResultEvent.RESULT, WebService_Results );
_getShipmentsToken.marker = ShipmentsEvent.LOAD;
}
Again, Service Capture shows the results coming in, and they all do come in correctly, but whichever result appears first is the only one that bubbles back and none of the other events get fired.
Very frustrating as you can imagine.
Thanks for your reply. I made the updates you suggested and still no love. The traces all show that, basically whichever event happens first, that one wins and all others are lost.
I moved the token definitions outside of the function and created a token for each method call.
I also added the event listener to the token itself.
public function GetShipments( custId:int ):void {
ws.addEventListener( ResultEvent.RESULT, WebService_Results );
_getShipmentsToken = ws.getShipmentsForCustomer
_getShipmentsToken.addEven
_getShipmentsToken.marker = ShipmentsEvent.LOAD;
}
Again, Service Capture shows the results coming in, and they all do come in correctly, but whichever result appears first is the only one that bubbles back and none of the other events get fired.
Very frustrating as you can imagine.
Have you turned on the logging capabilities of flex?
When im in my office again tomorrow, I could send you a code fragment to initialize the Flex log-framework. It helped me quite a lot when having similar problems.
Are you using the flexBuilder generated Webservice-client?
Whatever you are using, I would suggest setting a breakpoint in your event handler (The one that is called), step up one layer and have a look at the code there. When figguring out my problems regarding Flex + CXF + Aegis integration I had to do quite a lot of debugging in the Flex sources :-(
Chris
When im in my office again tomorrow, I could send you a code fragment to initialize the Flex log-framework. It helped me quite a lot when having similar problems.
Are you using the flexBuilder generated Webservice-client?
Whatever you are using, I would suggest setting a breakpoint in your event handler (The one that is called), step up one layer and have a look at the code there. When figguring out my problems regarding Flex + CXF + Aegis integration I had to do quite a lot of debugging in the Flex sources :-(
Chris
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you, Christofer...
Where does this log file get generated?
Where does this log file get generated?
Well the way it is configured in the sample I posted, it is generated in the Eclipse console of my Flex Builder. You can however let the debug version of the Flash player debug to a local file:
http://joelhooks.com/2008/08/12/super-automatic-trace-for-flex/
Here the link for the Debug version of the flash player:
http://www.adobe.com/support/flashplayer/downloads.html
http://joelhooks.com/2008/08/12/super-automatic-trace-for-flex/
Here the link for the Debug version of the flash player:
http://www.adobe.com/support/flashplayer/downloads.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ok ... the detail with the removeListener wasn't visible in your example ... Seems that this indeed seems to be the cause of your problems :-)
I'd suggest you close the question and don't add it to the knowledge-base.
I'd suggest you close the question and don't add it to the knowledge-base.
Could you try to add a trace-statement outside the switch statement? I would guess that the there are problems with the token, but it's just an assumption, as I was having similar problems.
Also I would try to change the callback signature to Event for debugging, because when using the different types of registering callbacks I had different types of events fired.
I would recomend adding the event listener to the token, that you are recieving or to the method. You are currently registering to events fired by the webservice itself.
Try:
var _getShipmentsToken:AsyncTo
public function GetShipments( custId:int ):void {
getShipmentsToken = ws.getShipmentsForCustomer
getShipmentsToken.addEvent
getShipmentsToken.marker = "shipments";
}
Notice the token is defined outside the function scope because I had problems otherwise. I guess as soon as flex leaves the function, the local variables are destroyed and so is the token.
Or (I am using the Flex Builder Webservice Adapters):
public function GetShipments( custId:int ):void {
ws.addgetShipmentsForCusto
var callToken:AsyncToken = ws.getShipmentsForCustomer
callToken.marker = "shipments";
}
Hope this helps,
Chris