Mega Code Archive

 
Categories / Flex / Data Model
 

Web Service Multiple Operations

<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">   <mx:Script>            import mx.controls.Alert;       import mx.rpc.events.FaultEvent;       import mx.collections.ArrayCollection;       import mx.rpc.events.ResultEvent;              [Bindable]       private var contactData:ArrayCollection;       [Bindable]       private var helloData:String;              private function contactsResultHandler(event:ResultEvent):void       {         contactData = event.result as ArrayCollection;       }       private function helloResultHandler(event:ResultEvent):void       {         helloData = event.result as String;       }       private function faultHandler(event:FaultEvent):void       {         Alert.show(event.fault.faultString, event.fault.faultCode);       }      </mx:Script>   <mx:WebService id="myService" wsdl="http://localhost/Service.cfc?wsdl" fault="faultHandler(event)">     <mx:operation name="getAllContacts" result="contactsResultHandler(event)"/>     <mx:operation name="helloWorld" result="helloResultHandler(event)"/>   </mx:WebService>      <mx:Button label="Get String" click="myService.helloWorld()"/>   <mx:Label text="{helloData}" />      <mx:Button label="Get Data" click="myService.getAllContacts()"/>   <mx:DataGrid dataProvider="{contactData}">     <mx:columns>       <mx:DataGridColumn dataField="firstName" headerText="First Name"/>       <mx:DataGridColumn dataField="lastName" headerText="Last Name"/>     </mx:columns>   </mx:DataGrid>    </mx:Application>