远程实例中的COM +调用方法未知名称错误 [英] COM+ invoking method in remote instance Unknown name error

查看:271
本文介绍了远程实例中的COM +调用方法未知名称错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个COM dll,我在我的.net项目中使用通过interop参考。现在我有一个要求将这个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和安装在我的客户端机器。使用以下代码到
访问此

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" });

但是我在调​​用Method_1时得到UNKNOWN NAME(0x80020006)错误?有任何一个面孔类似的问题之前,请帮助我。

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)初始后绑定代码:

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)

您也可以< a href =http://msdn.microsoft.com/en-us/library/tt0cf3sx%28v=vs.80%29.aspx =nofollow>从COM组件导入TLB ,如果你有很多类和这样的插件。

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

这篇关于远程实例中的COM +调用方法未知名称错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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