0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

@Jim Ford when you figure something out, please post the solution. It may help the rest of us.
the solution was: testWs = new WebService(); testWs.loadWSDL(wsdl); instead of testWs = new WebService(wsdl); testWs.loadWSDL(); see my edit above with formatting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.