Web Services, Part X: Consuming the StockQuote: Sending the Request - Doc JavaScript | WebReference

Web Services, Part X: Consuming the StockQuote: Sending the Request - Doc JavaScript


Web Services, Part X: Consuming the StockQuote

Sending the Request

The init() function sends the request to the Web service. First, it establishes a short name for the Web service:

service.useService(
  "https://www.eggheadcafe.com/webservices/StockQuote/
  Stockquote.asmx?WSDL", "StockQuote");

Notice that "service" is the name of the DIV element to which we attached the webservice behavior (see Page 2). The useService() method is one of the webservice behavior's interface methods, and is defined in webservice.htc. The Web service Stockquote.asmx resides on the eggheadcafe server. We give it the short name StockQuote, and this is how we reference it when we actually call the Web service:


iCallID = service.StockQuote.callService
  ("GetQuote", symbols.value);

The callService() function is defined in webservice.htc. It expects a request name ("GetQuote") and its arguments. The GetQuote request expects a string with trade symbols, separated by blanks. This string is entered by the user in the input text field with ID="symbols" (see callstockquote.html), and is passed to the GetQuote request as symbols.value. Notice also how we keep the returned ID of callService() in iCallID. This is needed for matching the response from the Web service to the triggering request. Here is the full listing of the init() function:

function init() {
  service.useService(
    "https://www.eggheadcafe.com/webservices/StockQuote/
    Stockquote.asmx?WSDL", "StockQuote");
  iCallID = service.StockQuote.callService("GetQuote",
    symbols.value);
}

Next: How to write the response handling function

https://www.internet.com


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

URL: https://www.webreference.com/js/column105/3.html