Main Page

createProxyAsync

onError: function (sMessage) {
//...
}
}
This object is passed into the
createProxyAsync()
method as in the following:
oFactory.createProxyAsync(“wsdl_location”, “port_name”, “”, true, oCallbackObject);
The
createProxyAsync()
method should always be called within a
try..catch
statement because it
throws an error if the method fails for any reason.
After this method is called, a new thread is started to load the WSDL proxy. When loaded, the
onLoad()
method is called and the new proxy is passed in. If you are only making a single Web service call, you
may want to have this method call the specific operation. Otherwise, you’ll probably want to store a ref-
erence to the proxy, such as this one, for later use:
var oProxy = null;
var oCallbackObject = {
onLoad: function (oCreatedProxy) {
oProxy = oCreatedProxy;
},
onError: function (sMessage) {
alert(sMessage);
}
}
In this example, a global variable named
oProxy
is created that stores the created proxy. In the
onLoad()
method, the created proxy is assigned into
oProxy
so it can be accessed in other functions.
Even though you can specify whether the proxy operations are called synchronously or asynchronously,
the synchronous calls don’t always work. It’s always best to use asynchronous calls.
To call an operation asynchronously requires yet another callback object. This object must have a call-
back method for each operation you intend to call. The name of the callback method is always the
name of the operation followed by
Callback
(for instance, the callback method for
getTemp
is called
getTempCallback
). This method receives as its arguments the response data from the Web service call.
To understand this better, it’s best to take a look at an example.
This example once again uses the Temperature Service. The important pieces of information are the
WSDL file location and the port name. Here are the global variables:
var oProxy = null;
var sWSDL = “http://www.xmethods.net/sd/2001/TemperatureService.wsdl”;
var sPort = “TemperaturePort”;
Next, you need a callback object for creation of the proxy. This simply assigns the created proxy to the
oProxy
variable and assigns a callback object for the operations using the
setListener()
method:
523
Web Services
20_579088 ch17.qxd 3/28/05 11:42 AM Page 523


JavaScript EditorFree JavaScript Editor     Ajax Editor


©