How to: Create a Serviced Component
The following procedure describes how to create a new serviced component.
To create a serviced component
Define a class that derives directly or indirectly from the ServicedComponent class. For example, the following code ensures that the Calculator class is hosted by a COM+ application.
Imports System.EnterpriseServices Public Class Account Inherits ServicedComponent Function Add (x as Integer, y as Integer) As Integer Add = x + y End Function End Class
Apply attributes to indicate how each assembly, class, or method should interact with COM+ functionality.
In .NET Framework version 1.1, the COM+ security configuration is enabled by default if the ApplicationAccessControlAttribute attribute is not present in the assembly. This is a change in behavior from .NET Framework version 1.0.
<Assembly: ApplicationName(“Calculator”)> <Assembly: System.Reflection.AssemblyKeyFile(“Calculator.snk”)> <MustRunInClientContext> _ Public Class Account Inherits ServicedComponent ‘ Member definitions. End Class
Generate a strong key and compile the following example:
Deploy the serviced component application by registering its assembly dynamically or manually.
After a serviced component is registered, clients can create instances of the component the way they create instances of any other component. For a complete example, see Serviced Component Example .
On Windows 2000 platforms, COM+ always loads the most recent version of the common language runtime for the component you are creating. This means that on a computer with both .NET Framework version 1.0 and .NET Framework version 1.1 installed, .NET Framework version 1.1 is always loaded. As a workaround, you can create a COM+ dllhost.exe.configuration file that enables you to “lock” all applications to a specific version of .NET Framework. On Windows XP and Windows Server 2003 platforms, the Application Root Directory setting can be used to point COM+ to an appropriate directory for its configuration file.
Imports System.EnterpriseServices <Assembly: ApplicationName(“Calculator”)> <Assembly: System.Reflection.AssemblyKeyFile(“Calculator.snk”)> <MustRunInClientContext> _ Public Class Account Inherits ServicedComponent Function Add (x as Integer, y as Integer) As Integer Add = x + y End Function End Class