6 Replies Latest reply on Jan 26, 2007 11:10 AM by tnirenstein

    Synronous Web Service Call

    tnirenstein
      Is there a way to make a web service call synchronously? In other words, I want to call the web service an wait for the result before continuing.

      Thanks!
        • 1. Re: Synronous Web Service Call
          What are you trying to accomplish here? Are you trying to keep the user from doing anything until the return of the service? Or are you trying to stop all processing until the return of the service? Becuase Flex 2 is an event-driven architecture, I'm not too sure you can do the second one. However, if you want to keep the users from doing thing, you could put the cursor to a wait cursor and disable your forms until the service returns.

          It really depends on why you need the web service call to be synchronous.

          --Andy
          • 2. Re: Synronous Web Service Call
            ur_dtrain Level 1
            Otherwise simply delay the call to the second service by placing it in the result handler for the first call. I do this frequently when the data needed for the second call relies on the value from first. This also allows me to disable functionality that relies on both. I've also simply set a flag that gets set once both have returned - each result handler checks the flag to see of it's ok to proceed.
            • 3. Re: Synronous Web Service Call
              tnirenstein Level 1
              That makes sense. Thanks for the idea. I'll use the result event handlers to synchronize the flow. One follow-up question. When you say, "each handler checks the flag to see if it's ok to proceed", how do you implement that? What if the flag indicates it is not ok to proceed yet. How do you wait for that flag to change before moving on without chewing up CPU with something like a "while" loop?

              Thanks!
              • 4. Synronous Web Service Call
                ur_dtrain Level 1
                Very simply.

                var ready:Boolean = false;

                function handler1():void{
                // result code
                if(ready){
                // other procedure already finished so proceed
                }else{
                // I finished first so set flag
                ready = true;
                }

                function handler2():void{
                // result code
                if(ready){
                // other procedure already finished so proceed
                }else{
                // I finished first so set flag
                ready = true;
                }

                This way the last one to finish, regardless of order, will initiate the next step(s).
                • 5. Re: Synronous Web Service Call
                  tnirenstein Level 1
                  got it, thanks!
                  • 6. Re: Synronous Web Service Call
                    tnirenstein Level 1
                    got it, thanks