↑
Main Page
Temperature Service
var oService = new WebService();
var vResult = oService.send();
alert(“Service returned “ + vResult);
This object, of course, doesn’t have enough information to be used on its own. However, it can be used
to create a wrapper for any other Web service.
The Temperature Service
Once again, it’s time to take a look at the Temperature Service. To do this, the
TemperatureService
object inherits from
WebService
and defines both the
url
and
action
properties:
function TemperatureService() {
WebService.apply(this);
this.url = “http://services.xmethods.net:80/soap/servlet/rpcrouter”;
this.zipcode = “”;
}
TemperatureService.prototype = new WebService();
Remember that the SOAP action for the Temperature Service is actually an empty string, so the default
value (inherited from
WebService
) is fine. A new property, zipcode, is used to store the zip code to check.
For the
buildRequest()
method, you first determine the format for the SOAP request. This can easily
be done for any Web service by using the WSDL analyzer tool available at XMethods (
http://www
.xmethods.net/ve2/Tools.po
). These methods enable you to see the request and response formats
for any Web service with a WSDL file.
The SOAP request for the Temperature Service looks like this:
<soap:Envelope xmlns:n=”urn:xmethods-Temperature”
xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/”
xmlns:soapenc=”http://schemas.xmlsoap.org/soap/encoding/”
xmlns:xs=”http://www.w3.org/2001/XMLSchema”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”>
<soap:Body soap:encodingStyle=”http://schemas.xmlsoap.org/soap/encoding/”>
<n:getTemp>
<zipcode xsi:type=”xs:string”>
<!--
zipcode here
-->
</zipcode>
</n:getTemp>
</soap:Body>
</soap:Envelope>
A whole lot of information is contained in this simple SOAP request, but the important line (which is
highlighted) is where the zip code should be entered. The
buildRequest()
method must create this
SOAP string with the zip code inserted:
TemperatureService.prototype.buildRequest = function () {
var oBuffer = new StringBuffer();
oBuffer.append(“<soap:Envelope xmlns:n=\”urn:xmethods-Temperature\” “);
oBuffer.append(“xmlns:soap=\”http://schemas.xmlsoap.org/soap/envelope/\” “);
527
Web Services
20_579088 ch17.qxd 3/28/05 11:42 AM Page 527
Free JavaScript Editor
Ajax Editor
©
→