gpt4 book ai didi

.net - 注册 regasm 和 regsvcs

转载 作者:行者123 更新时间:2023-12-02 15:43:28 26 4
gpt4 key购买 nike

我有以下问题:.NET 程序集是否可以同时注册到 Regasm 和 Regsvcs?谢谢

最佳答案

这是对该问题的超时回复。但让我解释一下我所意识到的差异。

为了理解这一点,您必须想出 COM 和 COM+ 应用程序之间的差异。

将您的类型注册为 COM -每次代码尝试初始化对象时按需创建对象

将您的类型注册为 COM+ 应用程序 - 创建对象、支持对象池、支持事务、支持增强的 Windows 安全性等等。

为了理解池化,我借用了 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 - 将 .net 程序集类型注册为 COM。这意味着 regasm 选择 .Net 程序集公开的类型,然后在 HKCR 写入适当的注册表项……; (这就是 regsvr32 的工作方式)。

  • regasm 可以为您生成 tlb 文件(就像 tlbexp.exe 一样)
  • regasm 可以为您的 .Net 程序集编写代码。也就是说,如果 GAC 中没有 .Net 程序集,那么您可以将 COM 编码到 .Net 程序集所在的文件位置。从这里,COM Marshaller 将选择使用 CLR 执行程序集。
  • regasm 允许您通过双击创建 .reg 文件,您可以更新注册表项。您必须确保 .Net 程序集已安装到 GAC,因为 regasm 中的/regfile 开关不允许您/codebase(如果它确实有 codebase,则毫无意义)

regsvcs - 从 .Net 程序集创建 COM+ 应用程序。这意味着 regsvcs 选择 .Net 程序集公开的类型,除了编写适当的注册表项之外,它还创建一个 COM+ 应用程序,您可以通过 Componet Services Manager 控制台 (%systemroot%\system32\comexp.msc )。

  • regsvcs 根据从命令行传递给它的信息或根据 .Net dll 提供的信息创建 COM+ 应用程序。

  • regsvcs 允许您将 COM+ 类型合并到现有的 COM+ 应用程序。查看 comexp.msc 以遍历了解 COM+ 应用程序和 COM+ 管理的 COmponets。

如果您使用 ComVisible(true) 编写 C# 类 --> 该类 (Foo) 的公共(public)类型已准备好通过 COM 的 regasm 进行注册。

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

如果您使用 ComVisible(true) 编写一个 C# 类,继承自 System.EnterpriseServices.ServicedComponent(当然还有更多设置..) --> 这个类 (FooBar) 已准备就绪注册为 COM+ 应用程序。

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

从 .Net 创建 COM+ 应用程序 - 您可以从这里开始。请记住,COM+ 为 COM 公开的对象提供了高级事务管理。

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

关于.net - 注册 regasm 和 regsvcs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8056517/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com