spacer

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

home / experts / javascript / column98


Web Services, Part III: WebService's Methods

The useService() Method

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

The useService method establishes a friendly name for a Web service. The friendly name is important for keeping your script short and compact. You can use the short friendly name instead of the Web service's long URL. Since you are going to reference the same Web service several times in your script, you are sure to appreciate this feature. Here is the syntax for calling the useService() method:


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 Web service 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. This parameter is optional. You can learn how to create this object in Page 4.

Here are some examples:

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

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

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

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

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

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 the 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:

function loadService() {
  webServiceCallerBody.onserviceavailable =
    enableServiceCall;  //Used for the synchronous call.
  webServiceCallerBody.useService(
    "http://soap.bluestone.com:80/interop/
      EchoService/EchoService.wsdl",
    "echo");
}

Next: How to use the callService() method

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


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

URL: http://www.webreference.com/js/column98/6.html