COM +的远程实例未知名称的错误调用方法实例、错误、名称、方法

2023-09-05 04:28:52 作者:要发光就先交电费

我有我是通过互操作使用全球化志愿服务青年在我的.NET项目一个COM DLL。现在我有一个要求,这个COM组件移动到另一个远程计算机并创建实例有(种出来的机器类似于进程外,大概这是远程的,我不知道: - ))

I have a COM dll which I was using in my .net project through interop referance. Now I got a requirement to move this COM component to another remote machine and create instance there.(kind of out of machine similar to out of process, probably this is remoting, i don't know :-))

我所做的是创造了一个新的COM + applciation在服务器计算机。添加了这个组件这个程序里面。这是它是如何列在COM +接口的服务器。

What I have done was created a new COM+ applciation in server machine. Added this component inside this app. This is how it is listed in COM+ interface on server.

导出这个应用程序的代理insatller并安装在我的客户机。使用下面的code到 访问此

Exported this app as proxy insatller and installed in my client machine. Used following code to access this

Type type;
type = Type.GetTypeFromProgID("DllName.COMName", "serverName", false);
var COMObject = Activator.CreateInstance(type);
var returnValue = COMObject.GetType().InvokeMember("Method_1",   BindingFlags.Public |  BindingFlags.InvokeMethod, null, COMObject, new object[1] { "1" });

不过,我收到未知的名称(0x80020006)错误调用Method_1什么时候?以前任何一个面对类似的问题,请大家帮帮我。

But I am getting UNKNOWN NAME (0x80020006) error when invoking Method_1? Have any one face similar issue before, please help me.

推荐答案

我会做的是这样的:

1)建立在C#中的等价接口,是这样的:

1) create an equivalent interface in C#, something like this:

[Guid("<the interface IID goes here>")]
public interface ISomeInterfaceName
{
   int Method1(...);
   int Method2(...);
   int Method3(...);
   ...
}

2),然后这个,而不是你最初的后期绑定code:

2) and then this, instead of your initial late-binding code:

Type type = Type.GetTypeFromProgID("DllName.COMName", "serverName", false);
var COMObject = Activator.CreateInstance(type);
var if = (ISomeInterfaceName)COMObject;
if.Method1(...);

注:IID必须IID的接口,而不是要与CLSID混淆。该方法应该进行布局精确到COM那些符合(该方法顺序很重要,参数和返回类型的定义如何也很重要)

NOTES: the IID must the IID from the interface, not to be confused with the CLSID. The methods should be laid out to correspond exactly to the COM ones (the methods order is important, how parameters and return type are defined is also important)

您也可以导入TLB 从COM组件,如果你有很多类和交互方法是这样的。

You could also import the TLB from the COM component, if you have a lot of classes and intefaces like this.