建筑采用4.0框架和Visual Studio 2010 COM互操作库ASP经典 [英] Building a COM interop library for ASP Classic using 4.0 framework and Visual Studio 2010

查看:298
本文介绍了建筑采用4.0框架和Visual Studio 2010 COM互操作库ASP经典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在经历了许多不同的文章,并没有找到这把我一步一步地完成整个过程的任何特别是确凿的,我是来寻求帮助。

After going through a number of different articles and not finding anything especially conclusive that takes me step-by-step through the process, I've come seeking help.

场景

我的一个客户是唯一精通发展 ASP经典。他们最近收购了一个帐户,原本写在ASP.NET网站。它们被轧的部位到东西,他们可以积极维护,但该网站最初包括的图像处理程序,动态地把有关的水位变化的数据,并输出包含该数据的图形重新presentation的图像。要求是开发一个 COM互操作可以在服务器上注册,并调用CreateObject来库生成使用响应相同的图像的字节数组输出。的BinaryWrite 。 COM互库必须在Windows 2000 Server上远程站点进行注册,我不能让他们有机会获得regasm / GACUTIL如何完成任务的任何假设。

A client of mine is only proficient in development for ASP Classic. They have recently acquired an account for a site originally written in ASP.NET. They are rolling the site into something they can actively maintain, but the site originally included an image handler that took dynamically changing data regarding water levels and outputs an image containing a graphical representation of that data. The requirement is to develop a COM interop library that can be registered on the server and called with CreateObject to generate the same image's byte array for output using Response.BinaryWrite. The COM interop library must be registered at the remote site on a Windows 2000 Server, and I can't make any assumptions about their having access to regasm/gacutil to accomplish that task.

的难度

我已经通过创建的类库的项目在Visual Studio 2010中,从模板中选择COM类,并插入我的code产生的一类具有内置的类库在给定一个整数(当然,枚举,但都是一样的)单一的公共方法返回一个字节数组。不幸的是,即使是在我自己的开发机器构建库和注册(regasm)和缓存组件(GACUTIL)后,我不能让通过经典ASP调用实例化对象,而不是收到一个的的ActiveX组件不能创建对象的错误。而且,当然,在服务器站点,DLL文件无法注册,响应为未找到必​​需模块。

I've built the class library by creating a Class Library project in Visual Studio 2010, choosing "COM Class" from the template, and inserting my code to generate a class with a single public method to return a byte array when given an integer (well, enumerator, but all the same). Unfortunately, even on my own development machine after building the library and registering (regasm) and caching the assembly (gacutil), I can't make a call through Classic ASP to instantiate the object, receiving instead an "ActiveX component can't create object" error. And, of course, at the server site, the DLL file can't be registered, the response being "Required module was not found."

资源我用

我已经有了通过以下的文章一看,并没有打开了我需要的答案:

I've already had a look through the following articles and haven't turned up the answers I need:

  1. (基本步骤)的 演练:创建COM使用Visual Basic
  2. 对象
  3. 构建和部署.NET COM组件
  4. .NET的COM +互操作组件与传统的ASP
  1. (Basic steps) Walkthrough: Creating COM Objects with Visual Basic
  2. Build and Deploy a .NET COM Assembly
  3. .NET COM+ Interop Component with Classic ASP

我需要什么

基本上我需要的是一个有点手拿着一种一步的是什么要采取符合要求,创造的 COM + 互操作正确的模块在Visual Studio 2010中创建实际的类对象本身并不十分困难。

Essentially what I need is a bit of hand-holding on a kind of step by step of what it's going to take to meet the requirements and create a COM+ interop module correctly in Visual Studio 2010. Creating the actual class object itself isn't terribly difficult.

然而,没有我看了看,通过真正的讨论项目方案或建立与Visual Studio 2010或.NET 4.0框架的程序,也没有任何人真的讨论是否有特殊的考虑部署到如老式系统的文章Windows Server 2000和图书馆的系统上的实际登记而已,比如, REGSVR32

However, none of the articles I've looked through really discuss project options or build procedures with Visual Studio 2010 or the .NET 4.0 Framework, nor have any of them really discussed if there are special considerations for deploying to older systems like Windows Server 2000 and the actual registration of the library on a system with only, say, regsvr32 on hand.

推荐答案

这应该是相当简单,以获得一个基本的.NET程序集暴露给COM - 我从来没有尝试过的COM类项目模板,所以这是我的样子已经设法它在过去的:

It should be fairly straightforward to get a basic .NET assembly exposed to COM - I've never tried the COM Class project template, so this is the way I've managed it in the past:

创建使用C#或VB一个新的(沼泽标准).NET类库。定义一个COM接口(替换为您自己的GUID):

Create a new (bog standard) .NET class library using C# or VB. Define a COM interface (replace GUIDs with your own):

[ComVisible(true)]
[Guid("8999F93E-52F6-4E29-BA64-0ADC22A1FB11")]
public interface IComm
{
    string GetMyGroups();
}

现在定义一个实现该接口的类(再次,替换为您自己的GUID):

Now define a class that implements that interface (again, replace GUIDs with your own):

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[GuidAttribute("C5C5A1A8-9BFB-4CE5-B42C-4E6688F6840B")]
[ProgId("Test.Comm.1")]
public class Comm : IComm
{
    public string GetMyGroups()
    {
        var comm = new CommunicatorAPI.MessengerClass();

        var groups = comm.MyGroups as IMessengerGroups;
        return string.Join(", ", groups.OfType<IMessengerGroup>().Select(g => g.Name).ToArray());
    }
}

在这个类的程序ID属性,你会用什么来从ASP实例化你的组件。

The Prog ID attribute on this class is what you will use to instantiate your component from ASP.

强烈名称的组件(项目属性 - >签名选项卡 - >程序集签名 - >使用下拉创建一个新的强名称密钥文件)

Strongly-name the assembly (Project properties -> "Signing" tab -> "Sign the assembly" -> Create a new strong name key file using the dropdown)

现在,建组装,并注册使用 Regasm - 如果你不希望在GAC注册(我会建议,尽量不要GACing保持部署简单),一定要使用 - codeBase的参数(这只是增加了一个reg项,告诉客户在哪里查找程序集) - 例如:

Now, build the assembly, and register using Regasm - if you don't wish to register in the GAC (which i'd recommend, as not GACing keeps the deployment simpler), be sure to use the -Codebase parameter (this just adds a reg entry that tells clients where to find the assembly) - e.g:

regasm ClassLibrary2.dll /codebase "S:\Testing\ClassLibrary2\ClassLibrary2\bin\Debug\ClassLibrary2.dll"

现在,你应该能够实例化组件,并调用方法就可以了 - 例如(在JavaScript):

Now you should be able to instantiate the component, and call methods on it - for example (in javascript):

var a = new ActiveXObject("Test.Comm.1");
alert(a.GetMyGroups());

当谈到部署,重要工作的Regasm和Regsvr32的做的是写各种设置到注册表,以便客户端可以找到COM组件(以程序ID,或COM类ID)。所有你需要做的是什么工作时,你的本地计算机上运行Regasm COM设置都被写入,并将它们写入服务器上的注册表。您可以使用将procmon 来监控被写入时Regasm运行注册表。

When it comes to deployment, the important work that Regasm and Regsvr32 do is to write various settings into the registry, so that clients can find the COM component (based on Prog ID, or COM Class ID). All you need to do is work out what COM settings are being written when you run Regasm on your local machine, and write these to the registry on the server. You can use ProcMon to monitor what gets written to the registry when Regasm is run.

一般来说,你可能会看到这样的事情写入注册表:

Generally speaking, you can expect to see something like this written to the registry:

[HKEY_CLASSES_ROOT\Test.Comm.1]
@="ClassLibrary2.Comm"

[HKEY_CLASSES_ROOT\Test.Comm.1\CLSID]
@="{00585504-90C8-4760-A359-67CAF08FFED1}"

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{00585504-90C8-4760-A359-67CAF08FFED1}]
@="ClassLibrary2.Comm"

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{00585504-90C8-4760-A359-67CAF08FFED1}\Implemented Categories]

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{00585504-90C8-4760-A359-67CAF08FFED1}\Implemented Categories\{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}]

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{00585504-90C8-4760-A359-67CAF08FFED1}\InprocServer32]
@="mscoree.dll"
"ThreadingModel"="Both"
"Class"="ClassLibrary2.Comm"
"Assembly"="ClassLibrary2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cf55d4e60653257a"
"RuntimeVersion"="v4.0.30319"
"CodeBase"="file:///S:/Testing/ClassLibrary2/ClassLibrary2/bin/Debug/ClassLibrary2.DLL"

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{00585504-90C8-4760-A359-67CAF08FFED1}\InprocServer32\1.0.0.0]
"Class"="ClassLibrary2.Comm"
"Assembly"="ClassLibrary2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cf55d4e60653257a"
"RuntimeVersion"="v4.0.30319"
"CodeBase"="file:///S:/Testing/ClassLibrary2/ClassLibrary2/bin/Debug/ClassLibrary2.DLL"

[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{00585504-90C8-4760-A359-67CAF08FFED1}\ProgId]
@="Test.Comm.1"

希望这有助于:)

Hope this helps :)

这篇关于建筑采用4.0框架和Visual Studio 2010 COM互操作库ASP经典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆