Main Page

Web Services in Mozilla

function callWebService() {
var sZip = document.getElementById(“txtZip”).value;
var oService = document.getElementById(“service”);
oService.useService(sWSDL, “Temperature”);
iCallID = oService.Temperature.callService(“getTemp”, sZip);
function onWebServiceResult() {
var oResult = event.result;
if ( == iCallID) {
var oDiv = document.getElementById(“divResult”);
if (oResult.error) {
alert(“An error occurred:” + oResult.errorDetail.string);
} else {
alert(“It is currently “ + oResult.value
+ “ degrees in that zip code.”);
The first function,
, gets the zip code from the text box and calls the Web service. It
first loads the WSDL file with the friendly name
. The next line uses the
method, passing in the operation name and the zip code.
The other function,
, displays the result of the call. This function uses the same
basic algorithm as the example earlier to check whether the result ID is equal to the call ID. It then reports
either an error or the returned value.
Web Services in Mozilla
Beginning in Mozilla 1.0, Web developers have had access to Web services. Mozilla currently supports
two ways of handling Web services: using a low-level SOAP API or using WSDL proxy objects (intro-
duced in Mozilla 1.4). Before exploring the WSDL-based functionality, it’s important to understand the
basic SOAP API.
Windows XP Service Pack 2 has some significant effects on the WebService compo-
nent. First, you must specify that files ending with .htc are served with a mime type
(this must be done on the server). Second, the WebService
component is forbidden access to external Web sites, meaning that you can only
access Web services hosted on the same server as the page attempting to call them.
Chapter 17
20_579088 ch17.qxd 3/28/05 11:42 AM Page 516

JavaScript EditorFree JavaScript Editor     Ajax Editor