3 Replies Latest reply on Nov 27, 2007 1:09 PM by ntsiii

    async trick/technique

    mae@ccg Level 1
      Hi,

      I've got a web service call that, depending on the data being requested, completes before or after another web service call.

      Is there a design pattern/trick/technique/something where I can call a method only after BOTH web service calls have completed?

      The only thing I can think of is setting a global "complete" boolean to true after each call completes. Then if both are true, call my method. This feels hackish to me and I'm just wondering if there is a better way.

      pseudo code:

      onWS1Result():void
      {
      ws1complete = true;
      tryMethod();
      }

      onWS2Result():void
      {
      ws2complete = true;
      tryMethod();
      }

      tryMethod():void
      {
      if (ws1complete && ws2complete)
      {
      dostuff();
      }
      }

      Any ideas/help/pointers would be great. Thanks.
        • 1. Re: async trick/technique
          ntsiii Level 3
          1) use a single WebService instance
          2) use a single result handler function
          3) Use AsyncToken to associate a result with a specific call

          The handler function can act as a "switchboard". When it gets a result labeled "myCall1", it can call a function, say doCall2(). Or it can do anything else you want.

          Do a bit of research, and post back if you need more help.

          Tracy
          • 2. Re: async trick/technique
            mae@ccg Level 1
            Tracy,

            Thanks for the pointers, but I'm not totally clear.

            Are you suggesting that I "chain" the calls together so that when one completes it calls the next? As an aside, do you find that to be more efficient - or faster - than calling two web services at once?

            I don't think I can use the same web service instance because the calls have different wsdls. Is that right/wrong?

            Thanks!
            • 3. Re: async trick/technique
              ntsiii Level 3
              You can set the wsdl property at will.

              If the order of the calls is not important, then do something similar to what you have suggested. Have the calling function increment an instance variable counter. Have the result handler and fault handler function decrement the counter. When it is zero, you wll know all of your calls have returned. Really, just like a flag, but more flexible.

              Tracy