Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Serviced Components

Visual Studio .NET 2003

Serviced components implement distributed transactions in Fitch and Mather 7.0. Classes that require .NET Framework Enterprise Services must do the following:

  • Inherit from System.EnterpriseServices.ServicedComponent class.
  • Apply service attributes to the assembly, class, or method.

For more information, see Serviced Component Overview and Summary of Available COM+ Services.

In Fitch and Mather 7.0, the DAL classes inherit from System.ServiceComponent.

The attributes of the DAL.Broker class and DAL.Account class require a new transaction as indicated below. Other classes of the DAL are marked for transaction support.

   [ Transaction( TransactionOption.RequiresNew ) ]
   [ ComVisible( true ) ]

Either of the following two methods finalizes transactions within a serviced component:

  • Attribute the code with [AutoComplete], in which case System.EnterpriseServices.ContextUtil.SetComplete method and System.EnterpriseServices.ContextUtil.SetAbort are called automatically based on whether there is an exception thrown.
  • Call SetComplete and SetAbort explicitly.

DisposeObject

Similar to cleaning up your own resources, other implicitly used resources, such as handles and context, also must be cleaned up. As System.EnterpriseServices.ServicedComponent implements the IDisposable interface, you could call the Dispose method on your serviced component and let the garbage collection service handle the cleanup. Calling the Dispose method on the serviced component would result in a context switch and a call to ServicedComponent.DisposeObject. Since garbage collection would require two cycles, the serviced component and its references remain in memory for a long time.

The process would be faster if you call ServicedComponent.DisposeObject directly. Fitch and Mather 7.0 makes this call from the Finally section of the error-handling construct of BLL.Broker.BrokerBuy:

   finally
   {
      if ( broker != null ) ServicedComponent.DisposeObject( broker );
      if ( ticker != null ) ServicedComponent.DisposeObject( ticker );
      if ( tx != null ) ServicedComponent.DisposeObject( tx );
   }

Registration

Fitch and Mather 7.0 dynamically registers serviced components. When the application tries to create a new instance of a managed class derived from System.EnterpriseServices.ServicedComponent, the runtime determines whether the component is already registered in a COM+ application. If it is not registered, all serviced components in the assembly are dynamically registered in a COM+ application.

Serviced components can also be registered manually by using the RegSvcs utility. For more information, see Microsoft .NET Framework Component Services, Part 1 (http://msdn.microsoft.com/library/techart/pahlcompserv.htm).

See Also

Architectural Overview | Buy Stock

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.