4 Replies Latest reply on Jul 21, 2009 8:23 AM by patniemeyer

    Flex 4 Web Service code generation changes...

    patniemeyer

      In Flex Builder 3 when I generated code from WSDL it gave me a synchronous, fully typed API.  I see that in Flash Builder 4 they are now returning an AsyncResult instead and they want you to bind to MXML.

       

      I would like to continue invoking my services through AS.  After some experimentation I was able to figure out that I have to register an event listener on the service object in order to recieve the result.  However I cannot see how one can get from this untyped item to the statically typed result without casting...  And furthermore I cannot see how I can use the generated result type object as it only has setters for the properties and not getters... at least with RPC style services.  When I tried a document style I see getters, however it's so awkward to use the document style from AS that I'd prefer not to.

       

      Is this just a work in progress or does Adobe not want us to use WS from AS any more?

       

      The FB3 tool produced better code...  It even generated examples in the comments based on the actual methods available.  It was great.

      I'd hate to lose it.

       

       

      Pat

        • 1. Re: Flex 4 Web Service code generation changes...
          patniemeyer Level 1

          One other problem with the change is that the Async API doesn't play well with testing in Flex Unit tests... since the tests generally exit before the result returns...  Has anyone found a way to unit test web sevice calls with the Flex 4 generated code?  I tried inserting a Pause into the code but it didn't keep the test alive.

           

           

          thanks,

          Pat

          • 2. Re: Flex 4 Web Service code generation changes...
            RaniKumar Level 2

            Hi,

             

             

            I am not sure about the  web service code generation differences. However related to using Flexunit,  have you used th addAsync option for testing the async calls?

             

            You can get details on addAsync at http://life.neophi.com/danielr/2007/03/asynchronous_testing_with_flex.html

             

             

            Thanks,

            rani

             

            • 3. Re: Flex 4 Web Service code generation changes...
              SunilAdobe Adobe Employee

              Thanks Pat,

               

              Let me try answering the questions one by one

               

              >>I see that in Flash Builder 4 they are now returning an AsyncResult instead and they want you to bind to MXML.<<

              FB3 was wrapping up the async result, the same thing can be done here. For example I used the web service http://www.webservicex.net/WeatherForecast.asmx?WSDL it has 2 operations both returning WeatherForecasts. After importing the service, I dragged and dropped the operation on a datagrid, FB4 generated the code for me to use the lastResult of the callResponder, something like this

               

              dataProvider="{GetWeatherByZipCodeResult.lastResult}"

               

              >>I would like to continue invoking my services through AS. <<

               

              You can invoke the calls through AS, the service that is created in the services folder, for example I created the weatherService and I was able to invoke my methods like this, however as you have indicated, we have to manually add the event handler for the response.

               

              var ws:WeatherService = new WeatherService();
              token = ws.GetWeatherByZipCode('12345');

               

              Do you require AS code to be generated as a preference instead of MXML? If so pls. log a bug and vote for it.

               

              >>

              After some experimentation I was able to figure out that I have to register an event listener on the service object in order to recieve the result.  However I cannot see how one can get from this untyped item to the statically typed result without casting.

              <<

               

              Are your operations returning strong types or are they being introspected as Object when they get imported. If it is Object, then we are planning to add the capability to configure the return type to a strong type, and then you need not cast it.

               

              I have filed the enhancement, you can vote for it.

               

              http://bugs.adobe.com/jira/browse/FB-21611

               

              >>And furthermore I cannot see how I can use the generated result type object as it only has setters for the properties and not getters... at least with RPC style services<<

               

              I was able to import the above mentioned WSDL and I could see the setters being generated in the file _Super_WeatherForecasts.as, can you recheck this.

               

              >>Is this just a work in progress or does Adobe not want us to use WS from AS any more?<<

               

              This is definitely work in progress and we would like more feedback like what you have already given. We would definitely like developers use AS as well as MXML, as I indicated you can use it in AS, but by default the code gets generated in MXML.

               

              >>It even generated examples in the comments based on the actual methods available<<

               

              FB3 did not have the User Interface Authoring feature (drag and drop the operation on a datagrid, or generate form, or the Data menu -> Bind data) and hence it had to put the usage guidelines. With FB4, we have tried that the developers can create user interfaces as mentioned above.

              But if you feel, a sample needs to be generated (for example, generate a datagrid for getWeatherForecasts for zip code 12345) needs to be there immediately as part of the service creation, pls. file the bug in http://bugs.adobe.com/flex

               

              Also, the following blog posts might be helpful

               

              http://raghuonflex.wordpress.com/2009/06/01/connecting-to-webservices-with-the-data-centri c-development-dcd-feature-in-flash-builder-4-part-1/

               

              http://srinivasannam.wordpress.com/2009/06/03/using-webservice-dcd/

               

              Hope this helps

              -Sunil

              • 4. Re: Flex 4 Web Service code generation changes...
                patniemeyer Level 1

                Thank you for your detailed response.  I do see that FB4 will generate the MXML code to bind a service to a component and I agree that this is very powerful.   My issue is simply that to use the generated code from AS has gotten a bit more awkward for two reasons:

                 

                1) FB3 used to generate a synchronous API.   Of course I do see the need to have an async API as well, but I think it would be convenient if FB4 simply generated both, as before.

                 

                2) The async API generated by FB4 is untyped - you have to cast the result of your event (possibly multiple times) to get the data.  I don't know if there is any way around this without generating more code, at least until AS gets generics.

                 

                e.g.

                 

                private function doCall():void {

                    var myService:MyService = new MyService();

                    var cr:CallResponder = new CallResponder();

                    cr.token = sms.getMessages(someArg);

                    cr.addEventListener(ResultEvent.RESULT, myHandler);

                }

                 

                 

                private function myHandler( event:ResultEvent ):void {

                    var messages:ArrayCollection = event.result as ArrayCollection;

                    var message:Message = messages.getItemAt(0) as Message;

                }

                 

                The tailored generated comments are not a big deal.  I only mentioned them because they were a really nice touch and an indication of some real sophistication in the tool.  It's just a shame to lose them.

                 

                 

                thanks,