How Do I: Poll Another Service for Information?
When you want to communicate with a web service that does not support asynchronous callbacks, you will have to poll the web service until the result is available. With polling, you call a function at regular intervals to check if the result is ready.
This is easy to accomplish using a Timer control.
To Add a Timer Control to Your Web Service for Polling
In Design View, select your web service.
From the Add Control drop-down list, select Add Timer Control.
In the dialog that appears, in step 1 of the dialog, enter a name for the variable that will represent your control (for example, you might enter timer). The name you enter must be a valid Java identifier.
In step 2 of the dialog, in the timeout-in box, enter the amount of time until the first poll should occur (for example, "0 sec").
In step 2 of the dialog, in the repeats-every box, enter the amount of time between polls (for example, "5 sec").
Call the timer's start method when you want to begin polling. Your code to start the timer might look something like this:
service.startOperation(); timer.start();
Each time the timer goes off, it will call your handler for the "onTimeout" callback. In this handler, you should call the web service to see if the information is available. Your code might look something like this:
private void timer_onTimeout(long time) { if (service.isOperationDone()) { timer.stop(); // process operation result... } }
Be sure to call stop method on the timer when you want to stop polling.