Chapter 14. Serviced Components and COM

I l @ ve RuBoard

Chapter 14. Serviced Components and COM+

COM is a powerful technology. In the old days, to build COM components successfully you had to understand how the "plumbing" worked ”you were forced to spend time worrying about building implementations of IUnknown , IDispatch , and other common interfaces before you could even begin to worry about implementing your business logic. Microsoft Visual Basic 6.0 changed that to some extent, generating much of the required boilerplate code for you automatically. The Microsoft .NET Framework goes a step further by generating COM callable wrappers (CCWs) for your classes if you want to expose them to COM clients . If you read the previous chapter, this is old news.

COM had its critics ”it was difficult to build scalable systems or manage distributed transactions or pool resources using COM. So Microsoft developed Microsoft Transaction Server (MTS), which became amalgamated with the Microsoft Windows 2000 operating system family as COM+. COM+ provides a range of features that are aimed squarely at developers who need to create high-performance, easily maintainable systems, including these:

  • Declarative transaction processing

    You can specify how a method published by a COM+ component should participate in a transaction ”whether it should create a new transaction, join an existing one, or be nontransactional. You can also indicate whether the transaction should commit or abort depending on the success or failure of the method. You achieve this using attributes rather than code.

  • JIT activation

    Objects can be deactivated when not in use. This feature conserves resources on the host server computer. When a client accesses a deactivated object, the COM+ runtime will silently activate a new instance of the object.

  • Object pooling

    The COM+ runtime can provide a pool of preinstantiated objects. An object can be obtained from the pool and activated on an as-needed basis when called by client code and then returned to the pool when the client has finished using it.

  • Role-based security

    You can specify the roles that are permitted to activate an instance of a component and use its methods . You can define these roles using attributes and query them in code. An administrator can assign users to these roles when the component is deployed.

  • Queuing

    A request to a COM+ component can be placed in a queue and executed asynchronously.

  • Loosely coupled events

    A COM+ component can raise events. Clients can select which events they want to be informed about. The coupling between a COM+ component's events and the clients that want to be notified is held in a database in the COM+ catalog. When an event is raised, the COM+ Event System queries the database, creates an instance of each client interested in the event, and then invokes the event sink method on each client object.

COM+ also has other features, such as the ability to import transactions from an outside environment (known as "Bring Your Own Transaction," or BYOT), compensating resource managers that allow you to implement transactional semantics with nontransactional resources, and interoperability with other processing models that are executing on other platforms through the COM Transaction Integrator. These features are beyond the scope of this chapter, which will instead concentrate on the core features previously listed.

If you're approaching J# development as an experienced Java 2 Enterprise Edition (J2EE) programmer, you'll notice many functional similarities between COM+ and the Enterprise JavaBeans (EJB) model. However, there are a number differences (some subtle, others not so subtle) that this chapter will make you aware of.

The use of declarative attributes in COM+ to request functionality from the component runtime should be familiar to you because these mechanisms are also used by the .NET Framework. There is good reason for this: Even though COM+ predates .NET, it was designed with .NET in mind.

The .NET Framework Class Library contains the System.EnterpriseServices namespace, which defines classes, attributes, and enumerations for interacting with COM+. You can build COM+ components and COM+ clients quickly and easily using the contents of this namespace. In the .NET world, COM+ components are referred to as serviced components .

Out of necessity, COM+ had to define its own infrastructure for managing issues such as security. Although the mechanisms used are similar to those of .NET, they are not the same, and they operate independently. This means you have to do a bit of work when you implement COM+ security from managed code. However, COM+ and .NET will merge seamlessly and become one in the not-too- distant future, eliminating such issues.

In this chapter, we'll take a good look at how to build COM+ clients and serviced components in J#. You'll learn how to invoke methods on a serviced component synchronously and asynchronously. We'll discuss how to use transactions and take advantage of COM+ object pooling, and we'll look at how to implement COM+ security.

Note

This chapter assumes that you have some familiarity with COM+ concepts (but you do not need to be an expert).


I l @ ve RuBoard


Microsoft Visual J# .NET (Core Reference)
Microsoft Visual J# .NET (Core Reference) (Pro-Developer)
ISBN: 0735615500
EAN: 2147483647
Year: 2002
Pages: 128

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net