1 Reply Latest reply on Feb 28, 2008 8:10 AM by ericbelair

    How to Retrieve Data From Web Service with Optional Arguments

    NuckNuck Level 1
      This should be a simple one. I have a web service that returns a list of books. There are 3 optional arguments that can be passed to this (ex. book type, author, id) to filter this list. Do I still need to use the <mx:request> tags if I am not going to pass any parameters to the web service?

      When I look at the services browser in Flex, it says "unable to get meta data for CFC". However, if I remove the arguments from the CFC and then call the service again, all my data now appears.

      What's the best way to appoach this?

      Thanks in advance
        • 1. Re: How to Retrieve Data From Web Service with Optional Arguments
          ericbelair Level 1
          I have a similar application. What I have done is create one argument in my CFC, with a type of "struct". Then, in the Flex Application, I create an Object (Associative Array), and pass this to the CFC as that one argument.

          Here is the ActionScript:

          // Create the variable to be passed to the WebService
          private var object:Object = new Object();

          Then in another function, you create the Object, based on specified values - perhaps from ComboBox selections:

          object.bookType = comboBox1.selectedItem["bookType"];
          object.author = comboBox2.selectedItem["author"];
          object.id = comboBox3.selectedItem["id"];

          Then you pass that one argument in your <mx:request>:

          <mx:WebService id="getBooks" wsdl" http://server.com/service.wsdl"
          <mx:operation name="sBooks">

          Your CFC might look like this:

          <cffunction method="sBooks">
          <cfargument name="args" type="struct">

          Then you can worry about validating the values passed to the CFC in the CFC function. That way, you could send an empty struct if you wanted, and the CFC would not throw an exception.

          Hope that helps.