Share via


COM+ Services

COM+ provides a number of services that make component and Web application development easier. These services are fully defined under the topics called Services Provided by COM+ and COM+ Services Without Components in the COM+ Software Development Kit (SDK) or online at COM+ (Component Services). The following is a short description of the services that can be used with ASP.

Since Side-by-Side assemblies is the only one which can be enabled using IIS Manager, example code is provided for enabling some services on an ASP application. All example code is written in VBScript and uses Windows Management Interfaces (WMI). WMI has an advantage over Active Directory Service Interfaces (ADSI) in that each flag of an IIS metabase property containing flags has its own WMI property. This makes the flags easier to set, and less prone to typographical errors that can break the ASP application. For all example code, the name of the Web server is MyMachine, and the user who runs the example code is assumed to have permission to administer the Web server.

For more examples of WMI scripts, see the WMI Tutorial, Module 3: Writing Administration Scripts that use WMI. For examples of ADSI scripts, see About IIS ADSI Objects. For a comparison between WMI and ADSI scripting in VBScript, JScript and Perl, see Code Examples to Configure Metabase Properties.

NewApartment Model Selection

ASP is now capable of running all of its threads in a multi-threaded apartment (MTA). If your COM components are primarily free-threaded or both-threaded, running the ASP threads as MTA can improve performance significantly.

To enable an ASP application to run in an MTA, you can use the metabase setting, AspExecuteInMTA, at the application level. This means that you can have one application running on ASP MTA threads and a second application running on ASP STA (single-threaded apartment) threads. The default for ASP threads continues to be STA.

important Important When you switch an ASP application from running in STA to MTA (or from MTA to STA), the impersonation token becomes obsolete. This can cause the application to run with no impersonation, effectively letting it run with the identity of the process which might allow access to other resources. If you must switch threading models, disable the application and unload it before you make the change.

The following example sets the Default Web Site application (W3SVC/1/ROOT) to execute in MTA:

  On Error Resume Next
set providerObj = GetObject("winmgmts://MyMachine/root/MicrosoftIISv2")
' Get a reference to the ASP application called Default Web Site
set IIsWebVirtualDirSettingObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT'")
WScript.Echo "Before: AspExecuteInMTA = " & IIsWebVirtualDirSettingObj.AspExecuteInMTA
' Set the ASP application to execute in MTA
IIsWebVirtualDirSettingObj.AspExecuteInMTA = 1
IIsWebVirtualDirSettingObj.Put_()
WScript.Echo "After: AspExecuteInMTA = " & IIsWebVirtualDirSettingObj.AspExecuteInMTA
NewSide-by-side Assemblies

Side-by-side (SxS) assemblies allow ASP applications to specify which version of a system DLL or classic COM component to use, such as MDAC, MFS, MSVCRT, MSXML, and so on. For example, if your ASP application relies on MSXML version 2.0, you can ensure that your application still uses MSXML version 2.0 even after service packs are applied to the server. Any new version of MSXML is still installed on the computer, but version 2.0 remains and is used by your application. Configuring SxS assemblies requires that you know the path to the DLL, and that the COM+ manifest file exists in every virtual directory that needs to use the DLL. The COM+ manifest is an XML file that has information about where a dll is installed. IIS does not verify that the manifest exists. A manifest looks like the following file excerpt:

  
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity publicKeyToken="75e377300ab7b886" type="win32" name="Test4Dir" version="1.0.0.0" processorArchitecture="x86"/>
<file name="DirComp.dll" hash="35ca6f27b11ed948ac6e50b75566355f0991d5d9" hashalg="SHA1">
<comClass clsid="{6C6CC20E-0F85-49C0-A14D-D09102BD7CDC}" progid="DirComp.PathInfo" threadingModel="apartment"/>
<typelib tlbid="{AA56D6B8-9ADB-415D-9E10-16DD68447319}" version="1.0" helpdir=""/>
</file>
</assembly>

You can enable side-by-side assemblies on the IIS side programmatically or by using IIS Manager.

To enable them by using IIS Manager, use the following procedure:

  1. Right-click a Web site or virtual directory and click Properties.
  2. Click the Virtual Directory tab, and click Configuration. If the configuration button is not enabled, it is because you have not created an application for this virtual directory. Click Create to create an application.
  3. In the Application Configuration dialog box, click the Options tab, and select Enable Side by Side assemblies.
  4. In the Manifest file name box, type the location of the COM+ manifest file name, and click OK twice.

To enable side-by-side assemblies programmatically, set the AspEnableSxs flag of the AspAppServiceFlags metabase property. Also set the AspSxsName metabase property to the name of the COM+ manifest name. Set both metabase properties at the application level.

important Important Only one version of a system DLL can be used in any application pool, even though this feature is configurable at the application level. For example, if application App1 uses MDAC version 2.5 and application App2 uses MDAC version 2.4, then App1 and App2 should not be in the same application pool. If they are, the application that is loaded first has its version of MDAC loaded, and the other application is forced to use it until the applications are unloaded.

The following example enables side-by-side assemblies on the Default Web Site application (W3SVC/1/ROOT). Notice that after setting only the AspEnableTracker property, the AspAppServiceFlags property changes as well:

  On Error Resume Next
set providerObj = GetObject("winmgmts://MyMachine/root/MicrosoftIISv2")
' Get a reference to the ASP application called Default Web Site
set IIsWebVirtualDirSettingObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT'")
WScript.Echo "Before: AspEnableSxs = " & IIsWebVirtualDirSettingObj.AspEnableSxs
WScript.Echo "        AspSxsName = " & IIsWebVirtualDirSettingObj.AspSxsName
WScript.Echo "        AspAppServiceFlags = " & IIsWebVirtualDirSettingObj.AspAppServiceFlags
' Set the ASP application to enable COM+ side-by-side assemblies
IIsWebVirtualDirSettingObj.AspEnableSxs = 1
' Set the AspSxsName property
IIsWebVirtualDirSettingObj.AspSxsName = "VersionInfo"
' Save the values to the IIS metabase
IIsWebVirtualDirSettingObj.Put_()
' Get the reference again in order to refresh the AspAppServiceFlags property.
set IIsWebVirtualDirSettingObj = Nothing
set IIsWebVirtualDirSettingObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT'")
WScript.Echo "After: AspEnableSxs = " & IIsWebVirtualDirSettingObj.AspEnableSxs
WScript.Echo "       AspSxsName = " & IIsWebVirtualDirSettingObj.AspSxsName
WScript.Echo "       AspAppServiceFlags = " & IIsWebVirtualDirSettingObj.AspAppServiceFlags
NewCOM+ Partitions

COM+ Partitions can be used to isolate Web applications into their own COM+ partitions. This is useful to prevent one Web application from accessing the private COM+ applications, configuration information, and data of another Web application. COM+ partitions can hold different versions of your own custom COM components. For example, if you host Web sites for two competing companies who both use COM+ in their Web applications, you can use COM+ partitions to ensure that one company's Web application cannot access the COM+ components in the other company's Web applications. If one of those companies asks you to change certain features in a COM+ application that they both use, you can isolate the new version of that COM+ application in the partition that is linked to their Web application.

To enable COM+ partitions on the IIS side, set the AspUsePartition flag of the AspAppServiceFlags metabase property at the application level. The partition is identified by a GUID (created using the Component Services Manager snap-in) which can be set at the AspPartitionID metabase property. If no partition is specified, the default system partition is used. For more information, please see the topic titled Creating and Configuring COM+ Partitions in the COM+ SDK or online at COM+ (Component Services).

important Important Only one version of a COM+ component can be used in any application pool, even though this feature is configurable at the application level. For example, if application App1 uses version 1.0 of a custom COM+ application called Shop.dll, and application App2 uses version 2.0 of Shop.dll, then App1 and App2 should not be in the same application pool. If they are, the application that is loaded first has its version of Shop.dll loaded, and the other application is forced to use it until the applications are unloaded.

The following example enables partitions on the Default Web Site application (W3SVC/1/ROOT). Notice that after setting only the AspEnableTracker property, the AspAppServiceFlags property changes as well:

  On Error Resume Next
set providerObj = GetObject("winmgmts://MyMachine/root/MicrosoftIISv2")
' Get a reference to the ASP application called Default Web Site
set IIsWebVirtualDirSettingObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT'")
WScript.Echo "Before: AspUsePartition = " & IIsWebVirtualDirSettingObj.AspUsePartition
WScript.Echo "        AspPartitionID = " & IIsWebVirtualDirSettingObj.AspPartitionID
WScript.Echo "        AspAppServiceFlags = " & IIsWebVirtualDirSettingObj.AspAppServiceFlags
' Set the ASP application to enable COM+ partitioning
IIsWebVirtualDirSettingObj.AspUsePartition = 1
' Set the AspPartitionID property to the GUID configured in Component Services Manager
' when you created the COM+ partition
IIsWebVirtualDirSettingObj.AspPartitionID = "{00000000-0000-0000-0000-000000000000}"
' Save the values to the IIS metabase
IIsWebVirtualDirSettingObj.Put_()
' Get the reference again in order to refresh the AspAppServiceFlags property.
set IIsWebVirtualDirSettingObj = Nothing
set IIsWebVirtualDirSettingObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT'")
WScript.Echo "After: AspUsePartition = " & IIsWebVirtualDirSettingObj.AspUsePartition
WScript.Echo "       AspPartitionID = " & IIsWebVirtualDirSettingObj.AspPartitionID
WScript.Echo "       AspAppServiceFlags = " & IIsWebVirtualDirSettingObj.AspAppServiceFlags
NewTracker

COM+ tracker allows administrators or developers to debug ASP applications. For example, if a Web application is causing problems on your server, you can enable COM+ tracker to determine when ASP pages are being loaded, when COM components are loaded, and when threads leave a page. Once you have debugged your application, you can disable COM+ tracker to return your application to normal performance speed.

To enable COM+ tracker on the IIS side, set the AspEnableTracker flag of the AspAppServiceFlags metabase property at the application level.

The following example enables tracking on the Default Web Site application (W3SVC/1/ROOT). Notice that after setting only the AspEnableTracker property, the AspAppServiceFlags property changes as well:

  On Error Resume Next
set providerObj = GetObject("winmgmts://MyMachine/root/MicrosoftIISv2")
' Get a reference to the ASP application called Default Web Site
set IIsWebVirtualDirSettingObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT'")
WScript.Echo "Before: AspEnableTracker = " & IIsWebVirtualDirSettingObj.AspEnableTracker
WScript.Echo "        AspAppServiceFlags = " & IIsWebVirtualDirSettingObj.AspAppServiceFlags
' Set the ASP application to enable COM+ tracking
IIsWebVirtualDirSettingObj.AspEnableTracker = 1
IIsWebVirtualDirSettingObj.Put_()
' Get the reference again in order to refresh the AspAppServiceFlags property.
set IIsWebVirtualDirSettingObj = Nothing
set IIsWebVirtualDirSettingObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT'")
WScript.Echo "After: AspEnableTracker = " & IIsWebVirtualDirSettingObj.AspEnableTracker
WScript.Echo "       AspAppServiceFlags = " & IIsWebVirtualDirSettingObj.AspAppServiceFlags
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 souces 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.

For more information on using the new component services from ASP applications, see Configuring Applications to use Component Services in the IIS product documentation or Using COM+ Services.