3 Replies Latest reply on Jun 11, 2010 5:01 AM by Ansury

    Return type Web Service



      I have a web service created in Java:


      public Vector<Data> getData();


      This is how I am connecting to the web service:


      public function connectWS():void{
           var cr:CallResponder = new CallResponder();
           cr.addEventListener(ResultEvent.RESULT, connectWSResult);
           cr.token = myWebService.getData();


      My vect variable above does not provide me with the correct Data object. vect is assigned null. How ever if I have:


      public function connectWSResult(event:ResultEvent);void{
           var arrCollect:ArrayCollection = event.result as ArrayCollection;


      arrCollection gives me correct value of Data object.


      I want the webService to return me a Vector. How can I go about that?



        • 1. Re: Return type Web Service
          Ansury Level 3

          If I understand you correctly (do not see a 'vect' variable anywhere), the web service is working perfectly.  The getData() function is non-blocking and does not "wait" for the response from the web service.  This is why you need to add an event listener, to listen for the "result" event.  When the reply comes in, the listener triggers the handler (connectWsResult) which you appear to have defined correctly.


          So I'm not sure what the problem is if you say the handler is returning the correct data.  Am I missing something?

          • 2. Re: Return type Web Service
            _H_P_ Level 1

            Hello Ansury,


            Yes, the web service works fine. The return type of the webservice is of type Vector and not ArrayCollections. I am getting a NULL when I invoke the result handler and store the result in Vector. However, I get the correct result when I store the result as an ArrayCollection.


            My question is, how do I make the result handler store the result in a Vector.



            • 3. Re: Return type Web Service
              Ansury Level 3

              You're skimming on the edge of my knowledge here (which is apparently getting a bit dated), I think Vector is Flex 4 only while I'm still using 2/3 mostly, but if it's giving you an ArrayCollection when converting from a Java Vector, that's the standard Java Collection-to-ArrayCollection behavior.  (I suppose they didn't alter the Java-Flex mappings in Flex 4.)  I would imagine that if you want to use a Vector on the Flex side you'll need to create a new Vector instance and put everything in the ArrayCollection into the Vector yourself. 


              In case you're not aware - you're getting a null when you do an "as" cast to Vector because the cast is failing (since it's not a Vector object).  (The type of object isn't decided by the cast, it's decided beforehand by Flex AMF deserialization code.)

              1 person found this helpful