Main Page

Web Services in Internet Explorer

The pertinent information (highlighted previously) from this file is the following:
?
The only operation is called
getTemp
.
?
The SOAP action for
getTemp
is “” (an empty string).
?
The target namespace for the input to
getTemp
is
urn:xmethods-Temperature
.
?
The name of the port is
TemperaturePort
.
?
The service location is
http://services.xmethods.net:80/soap/servlet/rpcrouter
.
Depending on the type of consumer used to access Web services, you may need to know some or all the
previous information.
Web Services in Internet Explorer
The folks over at Microsoft were kind enough to create an HTML component (also called a behavior)
that hides a lot of the ugly details from developers who wish to consume Web services. An HTML com-
ponent is essentially a COM component defined using XML and JavaScript. HTML components can
have properties, methods, and support custom events, making them ideal for creating functionality that
doesn’t exist in the browser by default. The downside is that only Internet Explorer supports HTML
components, and thus Microsoft’s
WebService
component does not work in other browsers. The
WebService
component is available for free from Microsoft’s Web site (
http://msdn.microsoft.com/
library/default.asp?url=/workshop/author/webservice/webservice.asp
).
Using the WebService component
After the
webservice.htc
file is downloaded, place it in the directory with your JavaScript files. You
can then access the functionality by applying it to an HTML element. To do this, use the
style
attribute
and the custom
behavior
CSS attribute:
<div style=”behavior(webservice.htc)”></div>
After doing this, the HTML element takes on all the properties, methods, and events of the
WebService
component. To use the component as a JavaScript object, just assign an ID to the element:
<div id=”service” style=”behavior(webservice.htc)”></div>
Then use the
document.getElementById()
method to retrieve a reference:
var oService = document.getElementById(“service”);
Next, you need to specify a Web service to use by calling
useService()
. The
useService()
method
accepts two parameters: the WSDL file describing the service and a friendly name for the service. A typi-
cal call looks like this:
oService.useService(sUrl, “FriendlyName”);
513
Web Services
20_579088 ch17.qxd 3/28/05 11:42 AM Page 513


JavaScript EditorFree JavaScript Editor     Ajax Editor


©