1 Reply Latest reply on Oct 28, 2006 8:20 PM by peterent

    Problem calling a CF-Webservice

    GFRLSSH
      Hello!

      I have a huge problem. For almost 2 weeks now, I'm on the same thing: I want to read and display a Database in Flex with help of a Coldfusion Webservice (CFC).

      That's what I have so far.


      This is my CFC-Webservice "readDB2.cfc"
      quote:


      <cfcomponent name="HelloWorld">

      <cffunction name="callDB" access="remote" returnType="query">
      <cfquery name="getCustomers" datasource="firma">
      SELECT mit_id, name, vorname, geschlecht, gehalt, abteilungsname
      FROM abteilung INNER JOIN mitarbeiter ON abteilung.abt_id = mitarbeiter.abt_id
      ORDER BY mit_id
      </cfquery>
      <cfreturn getCustomers>
      </cffunction>
      </cfcomponent>




      And here my try to get the data intro flex:
      quote:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="h*ttp://www.adobe.com/2006/mxml" layout="vertical">

      <mx:Script>
      <![CDATA[

      import mx.controls.Alert;
      import mx.rpc.http.HTTPService;
      import mx.rpc.events.FaultEvent;
      import mx.rpc.events.ResultEvent;

      private function getData():void
      {
      var service:HTTPService = new HTTPService();
      service.url = "h*ttp://testserver/carlos_flex_tests/readDB2.cfc?wsdl";
      service.addEventListener(ResultEvent.RESULT, resultHandler);
      service.addEventListener(FaultEvent.FAULT, faultHandler);
      service.send();
      }

      private function resultHandler(event:ResultEvent):void
      {
      dg.dataProvider = event.result.callDB.getCustomers;
      }

      private function faultHandler(event:FaultEvent):void
      {
      Alert.show("Es ist ein Fehler aufgetreten: " + event.fault.faultString, "Fehler!");
      }
      ]]>
      </mx:Script>

      <mx:DataGrid id="dg">
      <mx:columns>
      <mx:DataGridColumn dataField="name" headerText="Name"/>
      <mx:DataGridColumn dataField="vorname" headerText="Vorname"/>
      <mx:DataGridColumn dataField="gehalt" headerText="Gehalt"/>
      </mx:columns>
      </mx:DataGrid>

      <mx:Button label="Daten laden" click="getData()"/>

      </mx:Application>

      Well no errors so far. But it doesn't display any data either. And there is Data in the DB.
      Is there something wrong with my mx:HTTPService tag?





      And here another try with the mx:WebService-Tag:
      quote:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="h*ttp://www.adobe.com/2006/mxml" layout="vertical" creationComplete="wsReadDB.HelloWorld()">

      <mx:WebService id="wsReadDB"
      wsdl="h*ttp://testserver/carlos_flex_tests/readDB2.cfc?wsdl"
      useProxy="false"
      showBusyCursor="true" />

      <mx:DataGrid id="dg" width="100%" dataProvider="{wsReadDB.event.result.callDB.getCustomers}">
      <mx:columns>
      <mx:DataGridColumn dataField="name" headerText="Name"/>
      <mx:DataGridColumn dataField="vorname" headerText="Vorname"/>
      <mx:DataGridColumn dataField="gehalt" headerText="Gehalt"/>
      </mx:columns>
      </mx:DataGrid>

      </mx:Application>


      No success so far. No erros, neither while compiling nor while opening with the browser :-(
      Just no data displayed in the Datagrid. I think I get the data but I can't display it in the datagrid...
        • 1. Re: Problem calling a CF-Webservice
          peterent Level 2
          You can either use WebService or RemoteObject with CFCs; not HTTPService. I think RemoteObject is easier and it is faster since it is a binary exchange, not a text exchange as WebService.

          I also think creating data services in ActionScript is more trouble than it is worth unless you are building a very reusable framework. What's wrong with a simple <mx:WebService> or <mx:RemoteObject> tag?

          Your result handler should expect an argument of type ResultEvent. The event.result IS the result, you don't need to do event.result.callDB - that's no point to that and is probably the source of the problem. Check event.result and see what lies in that; use the Flex debugger to be certain.

          Your cffunction has a returntype of query; I'm curious to see what that actually returns to Flex. It might be an ArrayCollection which would be a good thing.