COM and COM+ Interview Questions 1

By | May 13, 2014

What are different transaction options available for services components ? There are 5 transactions types that can be used with COM+. Whenever an object is registered with COM+ it has to abide either to these 5 transaction types. Disabled: – There is no transaction. COM+ does not provide transaction support for this component. Not Supported: – Component does not support transactions. Hence even if the calling component in the hierarchy is transaction enabled this component will not participate in the transaction. Supported: – Components with transaction type supported will be a part of the transaction if the calling component has an active transaction. If the calling component is not transaction enabled this component will not start a new transaction. Required: – Components with this attribute require a transaction i.e. either the calling should have a transaction in place else this component will start a new transaction. Required New: – Components enabled with this transaction type always require a new transaction. Components with required new transaction type instantiate a new transaction for themselves every time.

Can we use com Components in .net?.How ?.can we use .net components in vb?.Explain how ? COM components have different internal architecture from .NET components hence they are not innately compatible. However .NET  framework supports invocation of unmanaged code from managed code (and vice-versa) through COM/.NET interoperability. .NET application communicates with a COM component through a managed wrapper of the component called Runtime Callable Wrapper (RCW); it acts as managed proxy to the unmanaged COM component. When a method call is made to COM object, it goes onto RCW and not the object itself. RCW manages the lifetime management of the COM component. Implementation Steps – Create Runtime Callable Wrapper out of COM component. Reference the metadata assembly Dll in the project and use its methods & properties RCW can be created using Type Library Importer utility or through VS.NET. Using VS.NET, add reference through COM tab to select the desired DLL. VS.NET automatically generates metadata assembly putting the classes provided by that component into a namespace with the same name as COM dll (XYZRCW.dll) .NET components can be invoked by unmanaged code through COM Callable Wrapper (CCW) in COM/.NET interop. The unmanaged code will talk to this proxy, which translates call to managed environment. We can use COM components in .NET through COM/.NET interoperability. When managed code calls an unmanaged component, behind the scene, .NET creates proxy called COM Callable wrapper (CCW), which accepts commands from a COM client, and forwards it to .NET component. There are two prerequisites to creating .NET component, to be used in unmanaged code: 1. .NET class should be implement its functionality through interface. First define interface in code, then have the class to imlpement it. This way, it prevents breaking of COM client, if/when .NET component changes. 2.Secondly, .NET class, which is to be visible to COM clients must be declared public. The tools that create the CCW only define types based on public classes. The same rule applies to methods, properties, and events that will be used by COM clients. Implementation Steps – 1. Generate type library of .NET component, using TLBExporter utility. A type library is the COM equivalent of the metadata contained within a .NET assembly. Type libraries are generally contained in files with the extension .tlb. A type library contains the necessary information to allow a COM client to determine which classes are located in a particular server, as well as the methods, properties, and events supported by those classes. 2. Secondly,  use Assembly Registration tool (regasm) to create the type library and register it. 3. Lastly install .NET assembly in GAC, so it is available as shared assembly.

What is Runtime Callable wrapper?.when it will created?. The common language runtime exposes COM objects through a proxy called the runtime callable wrapper (RCW). Although the RCW appears to be an ordinary object to .NET clients, its primary function is to marshal calls between a .NET client and a COM object. This wrapper turns the COM interfaces exposed by the COM component into .NET-compatible interfaces. For oleautomation (attribute indicates that an interface is compatible with Automation) interfaces, the RCW can be generated automatically from a type library. For non-oleautomation interfaces, it may be necessary to develop a custom RCW which manually maps the types exposed by the COM interface to .NET-compatible types.

What is Com Callable wrapper?when it will created? .NET components are accessed from COM via a COM Callable Wrapper (CCW). This is similar to a RCW, but works in the opposite direction. Again, if the wrapper cannot be automatically generated by the .NET development tools, or if the automatic behaviour is not desirable, a custom CCW can be developed. Also, for COM to ‘see’ the .NET component, the .NET component must be registered in the registry.CCWs also manage the object identity and object lifetime of the managed objects they wrap.

What is a primary interop ? A primary interop assembly is a collection of types that are deployed, versioned, and configured as a single unit. However, unlike other managed assemblies, an interop assembly contains type definitions (not implementation) of types that have already been defined in COM. These type definitions allow managed applications to bind to the COM types at compile time and provide information to the common language runtime about how the types should be marshaled at run time.

What are tlbimp and tlbexp tools used for ? The Type Library Exporter generates a type library that describes the types defined in a common language runtime assembly. The Type Library Importer converts the type definitions found within a COM type library into equivalent definitions in a common language runtime assembly. The output of Tlbimp.exe is a binary file (an assembly) that contains runtime metadata for the types defined within the original type library.

What benefit do you get from using a Primary Interop Assembly (PIA)? PIAs are important because they provide unique type identity. The PIA distinguishes the official type definitions from counterfeit definitions provided by other interop assemblies. Having a single type identity ensures type compatibility between applications that share the types defined in the PIA. Because the PIA is signed by its  publisher and labeled with the PrimaryInteropAssembly attribute, it can be differentiated from other interop assemblies that define the same types.

Leave a Reply