Web Services With Flex2

After getting everying working with the Asynchronous calls (see previous Post) I went a different direction. Tom had a good point that down the road, my result and fault handlers with huge Switch statements could, and most likely would get a bit unweildy. SO…

I went this route.

<mx:WebService id="personWS" wsdl="http://localhost:8101/cfusion/NameChange/Components/person.cfc?wsdl" fault="faultHandler(‘wsdlfault’, event)" showBusyCursor="true">
        <mx:operation name="personLogin" fault="faultHandler(‘Login’, event)" result="loginResult(event)" />
        <mx:operation name="echo" fault="faultHandler(‘echo’, event)" result="echoResult(event)" />
        <mx:operation name="addPerson" fault="faultHandler(‘addPerson’, event)" result="addPersonResult(event)" />
        <mx:operation name="getByID" fault="faultHandler(‘getbyid’, event)" result="getByIDResult(event)" />
    </mx:WebService>

Now I have specific result handlers and (if I wanted) specific fault handlers. I kept a universal fault handler for now, since all faults result in basically,

private function faultHandler(callerWS:String,eventObj:FaultEvent):void
               {
                switch(callerWS)
                {
                    case ‘Login’:
                        statusMSG = "There was a login error.  Please try again.";
                        break;
                    case ‘addPerson’:
                        statusMSG = "There was a problem registering.  Please try again.";
                        break;
                    case ‘getbyid’:
                        statusMSG = "There was a problem logging in.  Please try again.";
                        break;
                    case ‘endSession’:
                        break;
                    default:
                        break;
                }
               }

No need for extra code for that to be individual functions.

This approach seems to work very well. I’ve progressed quite far past the phase that was troubling me (again, see previous post). My App (still secret-esque) can log in a user, and register a user, and once in side, update that user’s profile. I’m happy.

Progress has slowed of late, I picked up a paying Flex project, so it gets a few more hours a day than this one does. GOtta pay the bills, and the car payment.