Поделиться через


IIS COM Components Overview

A COM component is a reusable, programmatic building block that contains code for performing a task or set of tasks. Components can be combined with other components (even across networks) to create a Web application. COM components execute common tasks so that you do not have to create your own code to perform these tasks. For example, you can use a stock ticker component to display the latest stock quotes on a Web page. However, it would be difficult to create a script that provides the same functionality. Also, the script would not be as reusable as a component.

About Components

If you are new to scripting, you can write scripts that use components without knowing anything about how the component works. ASP comes with base components that you can use immediately. For example, you can use the ActiveX Data Objects (ADO) components to add database connectivity to your Web pages. Additional components can also be obtained from third-party developers.

If you are a Web application developer, components are the best way to encapsulate your business logic into reusable, secure modules. For example, you could use a component to verify credit card numbers by calling the component from a script that processes sales orders. Because the verification is isolated from the order process, you can update the component when the credit card verification process changes, without changing your order process. Also, since COM components are reusable, you could reuse the component in other scripts and applications. Once you have installed a component on your Web server, you can call it from a ASP server-side script, an ISAPI extension, another component on the server, or a program written in another COM-compatible language.

You can create components in any programming language that supports the Component Object Model (COM), such as C, C++, Java, Visual Basic, or numerous scripting languages. (If you are familiar with COM programming, COM components are also known as Automation servers.) To run on the Web server, your COM components cannot have any graphical user interface elements, such as the Visual Basic MsgBox function; graphical interface elements would only be viewable on the server, and not the browser.

Uses of Components

You can develop components for use in a variety of Internet and intranet scenarios to implement business logic. In an Internet environment, for example, you might create a component that determines if a customer placing an order has sufficient credit to make a purchase. In an intranet environment, you might create a component that managers could use to update employee records in the company database. This section describes the event methods and interfaces available to components running on a Web server that supports Active Server Pages (ASP).

The first step in building a component is developing an appropriate design. Once you have a plan for developing your component, you will need to implement this plan using an appropriate development environment. You can implement your component using any development environment that is suitable for creating COM components. There are, however, some variations in how different environments approach this procedure. This section distinguishes between the requirements for implementing with script components, Visual Basic ?, Visual J++ ?, or Visual C++ ?. In addition, it describes implementation issues relating to security and type libraries.

Microsoft ? built Microsoft Windows Distributed interNet Application Architecture (Distributed interNet Applications) around the COM (Component Object Model) architecture. One of the most important contributions of COM is that it allows you to rapidly deploy solutions by re-using existing code. Before you build your application, therefore, you should organize the general functions of the application into distinct functional units. The process of defining component functionality is complex.

You should implement your server component as a DLL (in-process) server. A component implemented as a DLL runs in the same process as the Web application that contains the ASP script that creates the component instance. Running a component in-process with applications provides superior performance to out-of-process servers.

If you implement your component as an out-of-process server (an executable file), there are several issues that you should consider. These issues are discussed in Troubleshooting an ISAPI Failure .

To make best use of this section, you should be familiar with the Component Object Model (COM). For information about COM, see COM+ Programmer's Reference and COM+ (Component Services) in the COM+ software developer kit (SDK) or at MSDN Online.

You can use any language that supports Automation to develop your component such as script components, Microsoft ? Visual Basic ?, Microsoft ? Visual J++ ?, and Microsoft ? Visual C++ ?. The choice of language involves many considerations: your level of familiarity, tool support, run-time performance, threading models, code complexity, and the size of the compiled code.

Security should always be a primary consideration when developing components. See MS Press - Writing Secure Code for more information.

Transaction Processing

A transaction in the eCommerce world involves a series of operations where if one operation fails, the whole transaction fails. For example, when you buy a book from an online store, the operations may include updating the store's inventory, verifying that your credit card number is valid, charging your credit card, and initiating the shipment of your book. If any one of these operations fails, all changes must be cancelled or reversed. This technology, called transaction processing, is handled by COM+. Transaction processing is available to COM components and to ASP pages. Implementation in COM components involves calling the right COM interfaces. Implementation in ASP pages involves using the @TRANSACTIONdirective and the events of the ASP built-in object called ObjectContext Object.

Queued Components

Queued Components allow you to create components that can execute immediately if the client and server are connected. They provide an easy way to invoke and execute components asynchronously. In the event that the client and server are not connected, the component can hold execution until a connection is made. Queued Components assist the developer by using method calls similar to those calls used in component development, thus diminishing the need for an in-depth knowledge of marshaling.

COM+ Events

Component Services Events lets publishers and subscribers loosely connect to data sources so that these sources can be developed, deployed, and executed separately. The publisher does not need to know the number and location of the subscriber, and the subscriber uses an intermediate broker to find a publisher and manage the subscription to it. The event system simplifies component and Web application development by allowing both publisher and subscriber identities to be persistent: Publishers and subscribers identities can be manipulated without being known to each other.