Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Registration with regasm and regsvcs

Tags:

.net

com

com+

I have following question : Is it possible that .NET assembly will be regsitered both with Regasm and Regsvcs? Thanks

like image 880
lm. Avatar asked Nov 08 '11 20:11

lm.


1 Answers

This is a timed-out response for the question. but let me explain the differences I am aware of.

In order to understand this, you'd have to conjure up the differences between a COM and a COM+ Application.

Register your types as COM - Creates object on demand everytime a code tries to initialize the object

Register your types as COM+ application - Creates object, supports object pooling, supports transactions, supports enhanced Windows security and more.

To understand pooling, I am borrowing a response from http://www.tek-tips.com/viewthread.cfm?qid=116249

COM+'s main method of adding scalability and performance is done through object pooling. Unfortunately, this requires a free-threaded component, which is something VB6 cannot do. But... .NET (any language) and C++ can.

What object pooling does is you tell MTS/COM+ to create a pool of available objects, from a minimum that gets created when COM+ starts, to some maximum (which I don't know if it's a hard maximum, or if it's flexible). What pooling does for you is provide a caller with a pre-initialized object. This is much faster than waiting for an object to be created (especially over a network). The caller connects to the object, makes method calls, and disconnects. The object then goes back into the pool.

It does require a fundamental change in program architecture. Before COM+, everyone would open a connection to a database and leave it open for the duration of the application. This was OK when the user population was <100, as the load on the server was managable (each connection takes up RAM). But for large populations or unknown quantities of users (e.g. users from the Internet), the database server gets overloaded quickly. Someone realized that each transactional user was actually doing real work a small percentage of the time -- the rest of the time they were idle.

So your programs must make a connection, make a request, get the results, and then disconnect (this also applies to non-database objects). This also implies that the application be stateless (program state is not maintained between requests). Because... the object that you're currently using belonged to someone else 200 milliseconds ago. And when you get through using the object, another user will be using it after you. So the objects cannot keep any information around -- they must be code only.

regasm - Registers a .net assembly types as COM. What this means is the regasm picks the publicly exposed types of your .Net assembly and then writes appropriate registry entries at HKCR....; (which is the way regsvr32 works).

  • regasm can generate a tlb file for you (just like tlbexp.exe)
  • regasm can codebase your .Net assembly. That is if you dont have your .Net assembly in the GAC, then you can codebase the COM to the file location where the .Net assembly is present. And from here the COM Marshaller will pick the execute the assembly with CLR.
  • regasm allows you to create a .reg file by double clicking which you can update the registry entries. you have to make sure the .Net assembly is installed to the GAC becase /regfile switch in regasm does not allow you to /codebase (if it does codebase then it is meaningless)

regsvcs - Creates a COM+ Application from a .Net assembly. What this means is the regsvcs picks the publicly exposed types of your .Net assembly and besides writing the appropriate registry entries, it also creates a COM+ application that you can manage via the Componet Services Manager Console (%systemroot%\system32\comexp.msc).

  • regsvcs creates a COM+ application based on the information passed to it from the command line, or based on the information avaialble from the .Net dll.

  • regsvcs allows you to merge your COM+ types to an existing COM+ application. Take a look at comexp.msc to traverse through to understand a COM+ application and and COmponets that a COM+ manages.

If you write a C# class with ComVisible(true) --> The public types of this class (Foo) is ready to be registered with a regasm for COM.

    // Set the COM visibility attribute to true
[ComVisibleAttribute(true)]
public class Foo{....}

If you write a C# class with ComVisible(true), inheriting from System.EnterpriseServices.ServicedComponent (and more setting of course..) --> This class (FooBar) is ready to be registered as a COM+ application.

    // Set the COM visibility attribute to true
[ComVisibleAttribute(true)]
  public class FooBar: System.EnterpriseServices.ServicedComponent{.....}

Creating a COM+ application from .Net - You can begin here. Remember COM+ provides advanced transaaction mangement for a COM exposed object.

http://support.microsoft.com/kb/306296 http://my.execpc.com/~gopalan/dotnet/complus/complus.net_accountmanager.html http://www.codeproject.com/Articles/3845/Creating-COM-Objects-using-EnterpriseServices-in-N

like image 143
gmaran23 Avatar answered Oct 31 '22 13:10

gmaran23