2 Replies Latest reply on Sep 11, 2006 11:46 AM by ntsiii

    Accessing Web Service Results

    davidmedifit Level 1
      I am trying to call a web service, passing one parameter, and expecting one row from a database returned. My problem is accessing the results of the web service in labels, forms, etc. I have verified that the web service returns data, as I dumped it in a datagrid, and saw the results. (Note, the returntype from the web service is a query)

      My code is as follows:
      <mx:WebService id="libraryItemList" wsdl=" http://localhost/library.cfc?wsdl" useProxy="false">
      <mx:operation name="getItemDetails" fault="Alert.show(event.fault.message)">
      {dg.selectedItem.ITEMID} <!-- I am actually using a selected value in another datagrid as input -->

      Later, I try to access the data in the following manner:

      <mx:FormItem label="Item Name:">
      <mx:Text id="itemName" text="{libraryItemList.getItemDetails.lastResult.ITEMNAME}"/>
      <mx:FormItem label="Item Type:">
      <mx:Text id="itemType" text="{libraryItemList.getItemDetails.lastResult.ITEMTYPE}"/>
      <mx:DataGrid dataProvider="{libraryItemList.getItemDetails.lastResult}" id="dg2"/> <!-- I know the dataset is not empty, because I see it displayed in this datagrid -->

      Do I need to use a "result" function, and handle that way? I am returning a query from the web service - do I need to put that into an ArrayCollection or an Object? If you have insight as to what I am doing wrong, I'd appreciate the help.

      Thanks in advance,

        • 1. Accessing Web Service Results
          davidmedifit Level 1
          A quick update to say that I solved my problem.

          If anyone has better solutions, please let me know!

          What I did is as follows:

          First of all, I read on a post on flexcoders that I cannot access a query returned from a CF web service in the manner in which I was attempting (the post said that this was ok if I was using CF remoting via 7.0.2), and that I had to return either a struct or an array of structs. I returned a struct.

          Used a result handler for the web service call:
          <mx:WebService id="libraryItemList"
          wsdl=" http://localhost/library.cfc?wsdl" useProxy="false">
          <mx:operation name="getLibraryItems"/>
          <mx:operation name="getItemDetails" fault="Alert.show(event.fault.message)"

          The code to handle that is as follows:
          [Bindable] public var qItemDetails:Object;

          public function handleItemDetailsResult(event:ResultEvent):void{
          qItemDetails = event.result as Object;

          Accessed the variables with the following code:
          <mx:Text id="itemName" text="{qItemDetails.ITEMNAME}"/>

          I hope this helps, like I said, please do take a look at the code and tell me if there is some way I could have done it quicker / easier.


          • 2. Re: Accessing Web Service Results
            ntsiii Level 3
            That looks fine. Using an event handler function is not "necessary" but it makes debugging much easier. I always do just as you have, putting the result into a global variable.

            mx:Object is ok, but I am growing to like e4x xml as the resultFormat. The node navigation functionality is very robust, though you don't need that here.