1 Reply Latest reply on Aug 6, 2010 3:57 PM by ssardar

    Problem with getting sequences from Axis to Flex

    bolarum

      I ran into an interoperability problem between Flex and Axis when it comes to passing sequences of custom data types between Java server and Flex client. We absolutely must be able to pass arrays of simple DTOs between Flex and Java otherwise things become very messy, e.g. we won’t be able to use Flex data grids.

       

      Is this a problem for which there is already a well known solution?

       

      Thanks.

       

      Here is how to repro the problem.

       

      1.     Define a simple custom data type in Java:

       

      public class FooData {

              public String name1;

              public String name2;

       

              public FooData(String name1, String name2) {

                   this.name1 = name1;

                   this.name2 = name2;

              }

      }

       

      2.     Define and expose a Web service:

      @Service

      public class FooService {

             @Operation

             public FooData getData() {

                     return new FooData(“name1”, “name2”);

             }

       

            @Operation

            public FooData[] getDataList() {

                    return new FooData[] {new FooData(“name11”, “name12”), new FooData(“name21”, “name22”) };

            }

      }

       

      3.     Register the FooData type on client and server sides.

       

      4.     Try to run the service and call these operation from Flex.

       

      You will see that getData() operation works and getDataList() does not.

       

      What I tried:

       

      1.     Instead of passing objects I tried to pass XML as parameters to Web services calls and parse the XML on both sides. This works just fine on the java side. It works horribly on the Flex side. Too many manually manipulations with the data. The code becomes messy. Most importantly I ran into the same problem when passing XML that contains sequences of complex objects.

      2.     I tried BlazeDS. This framework is not that easy to use and my impression was that it may take us a couple of weeks before we can get comfortable with it and it is not guaranteed that we won’t dealing with a new set of problems.

       

        • 1. Re: Problem with getting sequences from Axis to Flex
          ssardar

          I do something similar from the Websphere Application Developer environment which I believe uses Axis2 as it's framework. (But it's integrated)

           

          I generate the wsdl files bottom-up for my Service endpoints.

           

          I have only had one minor issue and that is my objects all come in as a collection of Object Proxies, instead of using the Wsdl descriptions.  This is not a huge problem as I can cast Object proxies to Object as opposed to the actual class and use it just fine. (got this answer here)

           

          How are you making the call to the service?

          I have had some trouble using the generated classes as the service caller, as it returns a different format than the MXML call.  I will be playing with this this weekend to figure it out

           

          If your wsdl is fine, how are you handling the result when you make the call for the ArrayList?

           

           

          [

           

          Bindable]

           

          private var gridData:ListCollectionView;

           

           

          private function result(e:ResultEvent):void

          {

          gridData = e.result

           

          as ListCollectionView;

           

          }

           

           

           

           

          /**

          * The handleFaults() method is a very basic fault event handler method that

          * displays an Alert with the error message.

          *

          */

           

           

          public function faults(e:FaultEvent) : void

          {

          Alert.show(

           

          "A fault occurred contacting the server. Fault message is: "+e.fault.message);

          }

           

           

           

           

           

          <mx:WebService id="serviceID"

          wsdl="url of your wsdl"

          showBusyCursor="true">

           

           

          <mx:operation

          name="

           

          getDataList"

          result="result(event)"

          fault="fault(event)"

          />

           

           

          </mx:WebService>

           

           

           

           

          The above works for Arrays of complex types.  Let me know if you still have problems.

          You can just bind the ArrayCollection like I have, straight to your Grid or Advanced Grid.

          The only quirk is when you get objects out of the ArrayCollection for other things, you will have to cast them to Object instead of your class.  This will work but it will not show compile time errors if there are any when operating on the Object.

          I have yet to get this working from the generated Service.as class.