spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column97


Web Services, Part II: Calling Service Methods

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management

Loading the Web Service URL

A Web service is identified by a URL. The following is an example for a valid Web service:

http://soap.bluestone.com:80/interop/EchoService/
  EchoService.wsdl

It is quite cumbersome to use this URL every time you need to reference the Web service. The useService() method establishes a friendly name for a Web service URL, which can be referenced later from within the code. Here is the formal syntax:

sElementID.useService(sWebServiceURL, sFriendlyName
  [, oUseOptions]);

where:

  • sElementID is the ID of the element to which the WebService behavior is attached. This parameter is required.
  • sWebServiceURL is the WebService URL. This parameter is required. The path can be of four different types:
    • Web service file. It has an .asmx file extension. This short form of the URL is sufficient, provided that the Web service is located in the same folder as the Web page using the WebService behavior. In this case, the ?WSDL query string is assumed by the behavior.
    • WSDL file name. A Web Services Description Language (WSDL) file name. The WSDL file must have a .wsdl file extension.
    • Full file path. A full path to a Web service (.asmx) or WSDL (.wsdl) file. A file path to a Web Service must include the ?WSDL query string. Either a local file path or a URL can be specified.
    • Relative path. A relative path to a Web service (.asmx) or WSDL (.wsdl) file. A file path to a Web service must include the ?WSDL query string.
  • sFriendlyName is a string representing a friendly name for the Web service URL. This parameter is required.
  • oUseOptions is an instance of the useOptions object. It has a single property, reuseConnection, that specifies the persistence of the connection information required by Web services that use Secure Sockets Layer (SSL) authentication.

The following line assigns a friendly name to a Web service file (.asmx):

webServiceCallerBody.useService
  ("echoService.asmx","echo");

Notice that echoService.asmx must reside in the same folder as the Web page that calls the WebService behavior. Same rule applies when you call the WSDL file:

webServiceCallerBody.useService
  ("echoService.wsdl","echo");

The following line assigns a friendly name to a local disk file:

webServiceCallerBody.useService(
  "D:\legacy\yehuda\uyehuda\column97\
    echoService.asmx?WSDL","echo");

You have to add the ?WSDL query string also when you have a full HTTP path:

webServiceCallerBody.useService(
  "http://www.webreference.com/js/column97/
    echoService.asmx?WSDL","echo");

Suppose now that the Web service .asmx file is two levels up from the Web page (relative path):

webServiceCallerBody.useService(
  "../../echoService.asmx?WSDL","echo");

And finally, here is an example for an .asmx file residing in a subfolder beneath the Web page:

webServiceCallerBody.useService(
  "./subfolder/echoService.asmx?WSDL","echo");

To ensure that the useService method works correctly, you should place it inside an event handling function for the onload event. In this way, you will ensure that the first attempt to call a method in the behavior occurs only after the page has been downloaded and parsed. The event handling function may define friendly names for one or more Web Services. Here is an example:

<BODY ID="webServiceCallerBody" onload="loadService()"
  style="behavior:url(webservice.htc)">
<SCRIPT LANGUAGE="JavaScript">
<!--
function loadService() {
  webServiceCallerBody.useService(
    "http://soap.bluestone.com:80/interop/EchoService/
      EchoService.wsdl","echo");
  webServiceCallerBody.useService(
    "/services/math.asmx?WSDL", "MyMath");
}
// -->
</SCRIPT>

Next: How to send a message to a Web service

http://www.internet.com

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: November 19, 2001
Revised: November 19, 2001

URL: http://www.webreference.com/js/column97/3.html