|
|
One of the (current) key restrictions of the Webservice behavior is that the web service the behavior calls must reside on the same web server from which the HTML and the behavior itself were downloaded. You could not, for example, download an HTML page and behavior from www.yahoo.com and then use the behavior to directly call a web service that resides at www.microsoft.com.
If you need to call a web service that resides on a different server, you must create a web service that you can put on the same site as the HTML file and behavior, which will call the remote service on behalf of the behavior. In other words, you must create a web service that acts as a proxy.
In Chapter 2, you created the NestedCall web service, which provides the GetMSFT method, which itself uses a stock quote service from the XMethods website. The CallRemoteService.html file uses the NestCall web service, much like a proxy service, in order to retrieve and display the price of the Microsoft stock, as shown in Figure 3.9. Listing 3.8 implements the CallRemoteService.html file.
Listing 3.8 CallRemoteService.html
<html > <head> <title>Call Remote Service</title> <script language="JavaScript"> function InitializeService() { service.useService("http://localhost//NestedCall/Service1.asmx?wsdl", Ä "ProxyDemo"); } function CallProxy() { service.ProxyDemo.callService("GetMSFT"); } function ShowResult() { if (event.result.error) document.DemoForm.BoxText.value = event.result.errorDetail.string; else document.DemoForm.BoxText.value = event.result.value; } </script> </head> <body onload="InitializeService()" style="behavior:url(webservice.htc)" onresult="ShowResult()"> <form name="DemoForm"> <button onclick="CallProxy()">Retrieve Microsoft Stock Price</button><br> <textarea name="BoxText" Rows="5" Cols="60"></textarea> </form> </body> </html>
Figure 3.9: Using the Webservice behavior to interact with “local proxy” web service
|
|