↑
Main Page
SOAPFault
when there is no error, this is equal to 0. If the Web service itself causes the error, a
SOAPFault
object is cre-
ated and stored in the
fault
property of the
SOAPResponse
.
If there is a communication error, the error code is a number other than
0
. If the Web service itself causes
an error, then the
oResponse.fault
object is not
null
. This object has
faultString
and
faultCode
properties that provide additional details about the fault.
If there isn’t an error or a fault, you must get the data from the SOAP response. To do this, use the
getParameters()
method of the
SOAPResponse
object, which returns an array of the parameters
returned by the Web service:
var oParamCount = null;
var arrParams = oResponse.getParameters(false, oParamCount);
The first parameter of the
getParameters()
method indicates whether the response is in RPC format
or not. It is
false
for non-RPC and
true
for RPC (although using
false
works most of the time). The
second parameter is just an object that is filled with the number of parameters returned. In many cases,
the parameter count isn’t necessary because the number of parameters can be determined by using the
length
property on the returned array, and so typically the call is made like this:
var arrParams = oResponse.getParameters(false, {});
Note that, in this case, the second parameter is an object literal without a reference. The second parame-
ter must be included even if it isn’t used, so this is acceptable.
Each parameter has an
element
property that gives you access to the corresponding element in the
SOAP response. This is an XML element with all the methods and attributes of any XML element. To get
the string value of a parameter, you typically do something like this:
var sValue = arrParams[0].element.firstChild.nodeValue;
What you do with the value after that point, of course, is up to you.
To use the Temperature Service with the Mozilla SOAP objects, you need several pieces of information: the
Web service URL and the target namespace. Remember that this information is located in the WSDL file:
var sURL = “http://services.xmethods.net:80/soap/servlet/rpcrouter”;
var sTargetNamespace = “urn:xmethods-Temperature”;
The HTML for this example is the same as the IE example, with the exclusion of the extra
<div/>
ele-
ment needed for the
WebService
component.
It is also possible to call the service synchronously by using the
invoke()
method,
which returns a
SOAPResponse
object as its function value.
520
Chapter 17
20_579088 ch17.qxd 3/28/05 11:42 AM Page 520
Free JavaScript Editor
Ajax Editor
©
→