Listing 2: getWSDL Function
This function gets the WSDL document from the Web service. In this function we call the useService method of the myWebService service. We pass two parameters to this method. The first parameter is the URL of the Web service appended by "?WSDL." The second parameter is the friendly name of the Web service; you can use whatever name you like.
Listing 3: myWebService Example
When you view the style attribute of the div tag, you can see a bit of weird code. This is the heart of the HTML page from which we are deriving Web service consumption capabilities. I will explain the getResult function later.
Listing 4: Div Tag Style Attribute
In the HTML page, we are collecting an IP address as input. If you provide an invalid IP address you will get an error message. An IP address may not be your machine’s IP address if you are on a LAN; in that case, it will be the WAN IP of your internet gateway (e.g., a wireless router).
When you press the "getCountry" button, it calls the Lookup function via an onclick handler.
Listing 5: getCountry() Button Event
We now pass the method name of the Web service as the first parameter and the value of the IP address provided as second parameter. Once the result is sent back to the HTML page, it raises the result event, and then the getResult function is called. The getResult function was specified as the result event handler by the onresult parameter of the div tag shown in Listing 4.
Listing 6: getResult() Function
country.innerText = event.result.value;
This function assigns the result to the "country" span element.