Web Services, Part X: Consuming the StockQuote: The Caller Body - Doc JavaScript | WebReference

Web Services, Part X: Consuming the StockQuote: The Caller Body - Doc JavaScript


Web Services, Part X: Consuming the StockQuote

Writing the Caller Body

We explained in detail in Columns 97, 98, and 99 how to call (or consume, as some people like to call it) Web services. Let's practice it again with the StockQuote service.

The HTML page that calls StockQuote is callstockquote.html. This is the only HTML page you need to write. The other document you need to write is stock.xsl for pretty-printing the data coming from the Web service. The document callstockquote.html is 34-lines long, and is divided into four parts:

The HTML section instantiates the webservice.htc behavior and takes care of the user interface, for both the inputs and the outputs. We instantiate the webservice.htc behavior in a DIV element, but it can be associated with the document's BODY tag as well. The webservice.htc behavior does not do any I/O by itself, so it does not matter which tag you associate it with. Here is the DIV statement:

<DIV ID="service" STYLE="behavior:url(webservice.htc)" 
  ONRESULT="onWSresult()"></DIV>

Notice again the .htc extension of the behavior webservice. If your server does not let you download the file to a client browser, this extension is probably not defined in the server's mime.types table. Ask your server people to add the following statement to the mime.types table:

text/x-component htc  

The second part of callstockquote.html is the variable initialization section. This is a one-liner, initializing iCallID to zero:

var iCallID = 0; 

The variable iCallID is very important for synchronizing between the call to the Web service and its response. It's a unique signature for a particular call. Once you call a Web service you get this ID and keep it for further verification. When the response comes back from the Web service (takes a few seconds), it includes this unique signature. All we need to do is verify that the returned ID is equal to the ID we kept when sending off the request. This is how we make sure not to mix the responses to different requests.


Next: How to write the request handling function

http://www.internet.com


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: March 11, 2002
Revised: March 11, 2002

URL: http://www.webreference.com/js/column105/2.html