2 Replies Latest reply on Aug 14, 2009 1:33 AM by aaron_sf

    WebServices madness

    aaron_sf

      Is there one coherent, complete example in existence that demonstrates how to call a simple Web Service ?

       

      I have a web service all set up .. it's a simple thing .. just returns a string ... hello world stuff ....

       

      Over in Flex 3 .... I use the import Web Services wizard... and it generates a ton of code for me...

       

      ok great...

       

      now I need to know how to use that code via Actionscript (not MXML) ...

       

      I have found various snippets but not one complete example that actually works... even the adobe livedocs don't make any sense when you actually sit down and try to build-run them...!

       

      this shouldn't be so hard.... it's a hello world service returning a string ... and i'm 2 days into theis nonsense already ....

       

       

      help!

        • 2. Re: WebServices madness
          aaron_sf Level 1

          thanks Greg but this isn't what i'm looking for ...

           

          what I want to see is a complete 'hello world' example of using the actionscript classes that get generated by the WSDL importer. My understanding of this is that there are two basic ways you can go about this.... (1) in a static 'compile-time' way using the wsdl importer-code generator... and (2) in a dynamic 'run-time' way by using the generic WebService class and having that thing load the wsdl at runtime... and all of those links refer to scenario (2) ...

           

          so for example, I have a web service called 'MyWebService' and it has a method on it 'getTime()' that returns a string...

           

          running the wsdl importer, I would get a bunch of actionscript classes generated, including 'MyWebService.as' and 'BaseMyWebSevice.as'

           

          In my application code I would then expect to use an instance of MyWebService ... and call the generated methods on that....

           

          So for example :

           

          private var ws:MyWebService;

           

          public function doIt():void{

           

               ws = new MyWebService();

           

               ws.addGetTimeEventListener(resultHandler);                       // process the result in this handler

           

               ws.addMyWebServiceFaultEventListener(faultHandler);       // process faults here...

           

               ws.getTime_send();     // not sure this is correct....

          }

           

          public function faultHandler(event:FaultEvent):void{

               trace("FAULT: "+event.fault.faultString);

          }

           

          public function resultHandler(....){      // not sure how to declare this....

          }

           

          and so on ....   but I am screwing something up .. in this example, tracing into ws.getTime_send() ... it blows up for some reason I can't quite figure out...

           

          basically I just need to see a proper example of these GENERATED classes in action......

           

          there are some cryptic (to me anyway) comments in the generated code :

           

          * Actionscript sample code:
            * Step 1: create an instance of the service; pass it the LCDS destination string if any
            * var myService:MyWebService= new MyWebService();
            * Step 2: for the desired operation add a result handler (a function that you have already defined previously) 
            * myService.addgetTimeEventListener(myResultHandlingFunction);
            * Step 3: Call the operation as a method on the service. Pass the right values as arguments:
            * myService.getTime(mygetTime);

           

           

          so I think i'm sort of on the right track .. but I don't get what 'mygetTime' would correspond to ...

           

          UPDATE:

          making this up as I go along ... got a bit further with this:

           

                             ws = new MyWebService();
                             
                             var gt:GetTime = new GetTime();     // always wondered why this class got generated... 
                             
                              ws.addgetTimeEventListener(handle_result);
                             
                              ws.getTime(gt);

           

           

          now getting arg count mismatch in my declaration for the result handler... so now need to figure out what that might look like,,,

           

          gosh this is intuative...  

           

          UPDATE:

          ok ... answering my own question here... but hey .. i'm sure there are plenty of folks out there similarly confused...

           

          declaring the result handler like so :

           

               public function handle_result(event:GetTimeResultEvent):void{
                        trace("Response from service received.");
                        }

           

          got rid of the runtime error ... so I guess now I just need to figure out how to unpack the string...

           

          UPDATE ... drum roll please...

           

          public function handle_result(event:GetTimeResultEvent):void{
                        trace(ws.getTime_lastResult._return);
                        }

           

           

           

           

           

          (maybe I have been googling in the wrong places... but in 3 days of hair pulling I never saw a complete example of somebody actually using these generated classes....  everyone seemed to be using 'WebService'.....)