|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Introduction.NET is Microsoft's next-generation component technology. It is designed from the ground up to simplify component development and deployment, as well as to support interoperability between programming languages. Despite its innovations and modern design, .NET is essentially a component technology. Like COM, .NET provides you with the means to rapidly build binary components, and Microsoft intends for .NET to eventually succeed COM. Like COM, .NET does not provide its own component services. Instead, .NET relies on COM+ to provide it with instance management, transactions, activity-based synchronization, granular role-based security, disconnected asynchronous queued components, and loosely coupled events. The .NET namespace that contains the types necessary to use COM+ services was named Developing serviced componentsA .NET component that takes advantage of COM+ services needs to derive from the .NET base class
After a serviced component is registered, clients can create instances of the component the way they create instances of any other component. There are two ways to configure a serviced component to use COM+ services. The first is COM-like: you derive from .NET allows you to apply attributes to your serviced components with great flexibility. If you do not apply your own attributes, a serviced component is configured using default COM+ settings when it is added to a COM+ application. You can apply as many attributes as you like. A few COM+ services can only be configured via the Component Services Explorer. These services are mostly deployment-specific configurations, such as persistent subscriptions to COM+ events and allocation of users to roles. In general, almost everything you can do with the Component Services Explorer can be done with attributes. It is recommended that you put as many design-level attributes as possible (such as transaction support or synchronization) in the code and use the Component Services Explorer to configure deployment-specific details. Registering serviced componentsA serviced component is hosted by a COM+ application and must be accessible to that application. For accessibility, serviced components have the following registration and configuration requirements:
You can perform that registration in three ways:
Regardless of the technique you use, the registration process adds your serviced components to a COM+ application and configures them according to the default COM+ settings or according to their attributes (if present in the code). If the assembly contains incompatible attributes, the incompatibility is detected during registration and the registration is aborted. Future versions of the .NET compilers may detect incompatibilities during compilation time. Manual registrationTo register your component manually, use the RegSvcs.exe command-line utility. RegSvcs accepts as a parameter, the name of the file containing your assembly's metadata. In a single DLL assembly, that file is simply the assembly file. If you do not specify as an assembly attribute the name of the COM+ application that should host your components, RegSvcs must be told that name explicitly as a command-line parameter, using the /appname: switch. For example, if your single DLL assembly resides in MyAssembly.dll and you wish to add the serviced components in that assembly to the MyApp COM+ application, you would use RegSvcs in this manner: RegSvcs.exe /appname: MyApp MyAssembly.dll
The command-line application name is ignored if the assembly contains an application name. If you don't specify a COM+ application name, either in the assembly or as a command-line parameter, RegSvcs uses the assembly name for the application name. If your assembly is called MyAssembly, RegSvcs adds the components to the MyAssembly COM+ application. This behavior is the same for all the command-line switches. When RegSvcs adds a serviced component to the COM+ Catalog, it must give it a class-ID (CLSID) and a prog-ID. RegSvcs creates a GUID for every component (based on the assembly's version and the class definition) and names it < Namespace>.<Component name>. You can also specify the CLSID and the prog-ID of your serviced components using attributes. In addition to adding the serviced components in the assembly to a COM+ application, RegSvcs creates a type library. This library contains interface and CoClass definitions to be used by unmanaged clients (COM clients). The default type library filename is <Assembly name>.tlb--the name of the assembly with a .tlb extension. Dynamic registrationWhen a managed client creates a serviced component, the .NET runtime resolves which assembly version to use for that client. Next, the runtime verifies that the required version is registered with COM+. If it is not registered, the runtime installs it automatically. This process is called dynamic registration. As with RegSvcs, if the assembly contains an application name, then that name is used; if it does not, then the assembly's name is used for the COM+ application's name. Note that only .NET clients can rely on having dynamic registration done when they instantiate a .NET serviced component. For COM clients, you must use the RegSvcs utility. Another limitation of dynamic registration is that serviced components in the assembly are configured according to the attributes in the assembly and the COM+ defaults. If you require configuring some services (such as events subscriptions) using the Component Services Explorer for your application to function properly, you must use RegSvcs to register your components and provide the additional configuration using the Component Services Explorer. Only then can clients use your serviced components. As a result, dynamic registration is only useful for serviced components that contain all the service configurations they need in their code through the use of attributes. Finally, dynamic registration requires that the user invoking the call that triggers dynamic registration be a member of the Windows 2000 Administrators group. It has this requirement because dynamic registration makes changes to the COM+ Catalog; if the user invoking it is not a member of the Windows 2000 Administrators group, dynamic registration will fail. In general, you should use RegSvcs and the Component Services Explorer rather than relying on dynamic registration. If you want to rely on dynamic registration of your serviced components, you should increment the version number of your assembly every time you make a change to one of the components' attributes, to ensure that you trigger dynamic registration. Programmatic registrationBoth RegSvcs and dynamic registration use a .NET class called Public Sub InstallAssembly( _
ByVal assembly As String, _
ByRef application As String, _
ByRef tlb As String, _
ByVal installFlags As InstallationFlags _
)
The installation flags correspond to the various RegSvcs switches. See the MSDN Library for additional information on Configuring serviced componentsSpecifying application nameYou can provide .NET with an assembly attribute, specifying the name of the COM+ application you would like your components to be part of, by using the <Assembly: ApplicationName("MyApplication")>
If you do not provide an application name, .NET uses the assembly name. The imports System.EnterpriseServices;
The ApplicationID attributeEvery COM+ application has a GUID identifying it called the application ID. You can provide an assembly attribute specifying the application ID in addition to the application name: <Assembly: ApplicationID("8BE192FA-57D0-49a0-8608-6829A314EEBE")>
Unlike the application name, the application ID is guaranteed to be unique, and you can use it alongside the application name. Once an application ID is specified, all searches for the application during registration are done using the application ID only, and the application name is only useful as a human-readable form of the application identity. The Guid attributeInstead of having the registration process generate a CLSID for your serviced component, you can specify one for it using the imports System.EnterpriseServices;
<Guid ("260C9CC7-3B15-4155-BF9A-12CB4174A36E")> Public Class MyCls
Inherits ServicedComponent
'Code Here
End Class
The When you specify a class ID, subsequent registrations of the assembly don't generate a new CLSID for the component, regardless of the version of the assembly being registered. Registrations always reconfigure the same component in the COM+ Catalog. Specifying a class ID is useful during development, when you have multiple cycles of code-test-fix. Without it, every invocation by the test client triggers a dynamic registration--you very quickly clutter the COM+ application with dozens of components, when you actually only use the latest one. The ProgId attributeInstead of having the registration process generate a name for your serviced component (namespace plus component name), you can specify one for it using the imports System.EnterpriseServices;
<ProgId("MyClass.Web")> Public Class MyCls
Inherits ServicedComponent
'Code Here
End Class
The Application activation typeTo specify the COM+ application's activation type, you can use the <assembly: ApplicationActivation(ActivationOption.Server)>
or:
<assembly: ApplicationActivation(ActivationOption.Library)>
If you do not provide the The Description attributeThe COM+ object poolingThe <ObjectPooling(MinPoolSize=3,MaxPoolSize=10,CreationTimeout=20)>
Public Class MyClass
Inherits ServicedComponent
'Code Here
End Class
The COM+ constructor stringAny COM+ configured component that implements the Public Class Web
Inherits ServicedComponent
Protected Overrides Sub Construct( _
ByVal constructString As String)
If Not constructString Is Nothing Then
mstrConstructionString = constructString
End If
End Class
The If the checkbox "Enable object construction" on the component activation tab is selected, then the You can also enable construction string support and provide a default construction string using the <ConstructionEnabled(Enabled=true, Default = "My String")>
Public Class Web
Inherits ServicedComponent
End Class
The COM+ transactionsYou can configure your serviced component to use the five available COM+ transaction support options by using the
For example, to configure your serviced component to require a transaction, use the <Transaction(TransactionOption.Required)> Public Class Web Inherits ServicedComponent End Class Strong named assembliesA strong name consists of the assembly's identity---it's simple text name, version number, and culture information (if provided)---plus a public key and a digital signature. It is generated from an assembly file (the file that contains the assembly manifest, which in turn contains the names and hashes of all of the files that make up the assembly), using the corresponding private key. Once an assembly is created, you cannot sign it with a strong name. To create a strong-named assembly, you must sign it with a strong name when you create it. For creating a strong named assembly, you need to create a cryptographic key pair using the Strong Name tool (Sn.exe) and assign that key pair to the assembly using either a command-line compiler or the Assembly Generation tool (Al.exe). The .NET Framework SDK provides both Sn.exe and Al.exe. To create a key pairAt the command prompt, type the following command: sn –k <file name>
In this command, sn -k sgKey.snk
Signing an assembly with a strong nameThere are two ways to sign an assembly with a strong name:
To create and sign an assembly with a strong name using the Assembly Generation toolAt the command prompt, type the following command: al /out:<assembly name> <module name> /keyfile:<file name>
In this command, The following example signs the assembly MyAssembly.dll with a strong name using the key file sgKey.snk. al /out:MyAssembly.dll MyModule.netmodule /keyfile:sgKey.snk
To sign an assembly with a strong name using attributesIn a code module, add the
Installing an assembly into the Global Assembly CacheWhen an assembly that uses There are two ways to install an assembly into the Global Assembly Cache:
To install a strong-named assembly into the Global Assembly CacheAt the command prompt, type the following command: gacutil –i <assembly name>
In this command, gacutil -i hello.dll
ConclusionThis article explains how to develop and deploy serviced components in Visual Basic .NET. It also explains about custom attributes which is used in COM+ services.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||