Reputation: 1111
I'm new to flex and I am building a wrapper class for the WebService object to make my main code mxml cleaner. I am trying to pass a function to a class method to set as the result event handler for the soap call and it is not working as expected.
Here is the class:
package
{
import mx.rpc.events.ResultEvent;
import mx.rpc.soap.WebService;
public class WebServiceObject
{
private var wsdl:String = "http://localhost:8080/WebApplication1/TestWs?wsdl";
private var testWs:WebService;
public function WebServiceObject()
{
try {
testWs = new WebService(wsdl);
testWs.loadWSDL();
} catch(errObject:Error) {
trace(errObject.toString());
}
}
public function getSomething(resultHandler:Function):void
{
testWs.getSomething.addEventListener(ResultEvent.RESULT, resultHandler);
testWs.getSomething.send();
}
}
}
This is the mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<![CDATA[
import WebServiceObject;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
private function test():void
{
var test:WebServiceObject = new WebServiceObject();
test.getSomething(handler);
}
public function handler(event:ResultEvent):void
{
trace(event.result);
}
]]>
</mx:Script>
<mx:Button label="Test" click="test();"/>
</mx:Application>
The web service call is started and the call goes out but the result does not get passed back to the event listener. I tried using a class method as the handler and got the same result. All the pieces work if they are in the mxml code tag.
Is this doable? Am I missing something?
Thanks.
EDIT:
OK apparently (this didn't work):
testWs = new WebService(wsdl);
testWs.loadWSDL();
is not the same as (this did work, note where the wsdl URL is passed in):
testWs = new WebService();
testWs.loadWSDL(wsdl);
and I was quite sure that I tried it both ways... anyway problem solved.
Upvotes: 0
Views: 617
Reputation: 5495
This should be working from the looks of things. Perhaps the WebServiceObject is being garbage collected before the event fires? Try storing it in a Class level variable. It does seem odd.
Upvotes: 1