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 Controls in the Insert Menu, select
Timer.
-
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
field, enter the amount of time until the first poll should occur (for
example, 5 seconds).
-
In Step 2 of the dialog, in the repeats-every
field, enter the amount of time between polls (for example, 5
seconds).
-
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 calls 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 the stop method on the
timer when you want to stop polling.