15
SOAP and Web Services
Using SOAP and Web Services
Asynchronous Web Service Calls
The
SOAP
object’s
request
method may be used in conjunction with the
response
method to establish asynchronous communication with a web service. In this case, the
request
method calls a method on the notification object, and does not return a value.
Asynchronous communication is made possible by assigning a value to the
request
method’s
aSync
parameter, which is an object literal that must contain a function called
response
that accepts two parameters:
oResult
(the result object) and
cURI
(the URI
of the requested HTTP endpoint).
In the example below, the
aSync
parameter named
mySync
contains an attribute called
isDone
, which is used to monitor the status of the web service call, and an attribute called
val
which will contain the result of the web service call. When the
response
function is
called by the web service, it sets
isDone
to
true
indicating that the asynchronous call has
been completed:
// Create the aSync parameter:
var mySync = {
isDone: false,
val: null,
// Generates the result of the web method:
result: function(cMethod)
{
this.isDone = false;
var name = "http://mydomain/methods/:" + cMethod + "Response";
if (typeof this.val[name] == "undefined")
return null;
else
return this.val[name]["return"];
},
// The method called by the web service after completion:
response: function(oResult, cURI)
{
this.val = oResult;
this.isDone = true;
},
// While the web service is not done, do something else:
wait: function()
{
while (!this.isDone) doSomethingElse();
}
};
250
Acrobat JavaScript Scripting Guide