Using the Webservice Behavior

xiaoxiao2021-03-06  107

Using The Webservice Behavior Internet Development Index

This article explains how to use the WebService behavior to call remote methods from Web Services. The WebService behavior is implemented with an HTML Component (HTC) file as an attached behavior, so it can be used in Microsoft Internet Explorer 5 and later versions. Most of this article focuses on how to use the WebService behavior, but it also touches briefly on Web Services that are used by the WebService behavior The About the WebService behavior provides additional discussion and information on the main benefits and features of the WebService behavior;. it Also provides numerous links to related web sites.

The Following Topics Are Discussed in this Document.

Terminology Attaching the WebService Behavior Identifying Web Services Calling Methods on Web Services Handling Results from WebService Calls The Call Object SSL Authentication Calling Methods on Remote Servers Related Topics

TERMINOLOGY

THIS Section Defines Certain Terms That Are Used Frequently In this article.

Web ServiceProgrammable application logic accessible using standard Internet protocols. Web Services provide well-defined interfaces, or contracts, that describe the services provided. The WebService behavior uses Web Services.WebService behaviorThe primary subject of this article. A reusable DHTML component that uses Web Services .

Attaching the Webservice Behavior

The first step in using the WebService behavior is to attach it to an element using the STYLE attribute. It is also necessary to set the id attribute so that this element can be easily referenced in script, as shown in the following example.

This is all that's needed to attach the behavior to the document. The behavior can also be applied using other variations of Cascading Style Sheets (CSS) style sheet syntax. To begin working with the WebService behavior, it is easiest to download the WebService HTC File and copy it to the same directory as the Web page that uses the behavior. By referencing a local file, any Dynamic HTML (DHTML) behavior-related cross-domain security issues are avoided, and the WebService HTC File download is invisible to the client .

That...............

Identifying Web Services

Any given Web Service exists at a specific URL, so the WebService behavior provides the useService method to map the Web Service URL to a FriendlyName, which is passed as a parameter to the method. After this method has been called, the friendly name for the Web Service Can Be Used Directly In Script To Reference The Web Service URL, Which Helps To Keep The Script Code Readable and as Simple As Possible.

The Basic Syntax of The UseService Method Is as Follows:

ID.useService ("ServiceURL", "FriendlyName");

The id that the useService method is applied on is the value of the id attribute specified on the HTML tag to which the behavior is attached. Based on the preceding behavior attachment sample, the following snippet shows how the useService method can be coded.service. UseService ("/ services / math.asmx? wsdl", "mymath");

Note

The specification of the? WSDL query string at the end of the URL means that a Web Services Definition Language file describes the Web Service. The WSDL file consists of Extensible Markup Language (XML) file with a .xsd file extension. This WSDL file describes The Web Service Class, Which Is Reference In Script by The Friendly Name Mymath. The WebService Behavior Supports WSDL Version 1.1, See Web Services Description Language (WSDL) 1.1 for more information.

Once the useService method has been called, the Web Service can be addressed by its friendly name MyMath. It is recommended that the friendly name used in the client script matches the class name that implements the methods being called, but this is not a requirement. to ensure that the useService method works correctly, it should be placed inside a handler for the onload event, so that the first attempt to call a method in the behavior only occurs after the page has been downloaded and parsed. The code placed inside this handler May Define Friendly Names for One or more Web Services. The Following Sample Shows How this Can Be Accomplished.