Jun 22 2008

Cairngorm and Web Services

Published by at 1:17 pm under Flex

I had to use Cairngorm where the data was coming from web services and i had little trouble initially setting up services in my command class. But after a few tries and misses i was able to get web services to work. This is how i have implemented it.

Service class just defines a webservice as follows,

 

Pretty straightforward and the services are global so any changes in the server can be easily changed. Now the execute method of the command class which calls this service looks like this.

 

public function execute(event:CairngormEvent):void {
    var service:WebService;
    var operation:Operation;
    var token:AsyncToken;
    var requestObj:Object;
    var email:String = event.data.email;
    var password:String = event.data.password;

    service = ServiceLocator.getInstance().getWebService("signUpService");
//load the wsdl file
    service.loadWSDL();

//we assign the operation to the function that needs to be called inside the wsdl
    operation = service.getOperation("GetItemsFromStore") as Operation;
//the result format we need is e4x
    operation.resultFormat = "e4x";
//this object will pass all the required parameters for this function
    requestObj = new Object();
    requestObj.email = email;
    requestObj.password = password;
    operation.request = requestObj;
    token = operation.send() as AsyncToken;
//this is the line where the responder object is passed to the Asynctoken
    token.addResponder(event.data.responderObj);

}

Disclaimer: The above code is a copy paste and then modified so please forgive the coding style.

Now the fault or the result method of our responderObj will be called accordingly.

One response so far

One Response to “Cairngorm and Web Services”

  1. cette pageon 29 Dec 2017 at 2:16 am

    I visited many websites Ьut the audio quality forr audio songs current аt thіs
    website is genuinely excellent.

Trackback URI | Comments RSS

Leave a Reply