Using a Web Service As a Proxy

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

start example
<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> 
end example

click to expand
Figure 3.9: Using the Webservice behavior to interact with “local proxy” web service




. NET Web Services Solutions
.NET Web Services Solutions
ISBN: 0782141722
EAN: 2147483647
Year: 2005
Pages: 161
Authors: Kris Jamsa

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net