如何从 C# 调用 DCOM 对象?

发布于 2024-09-30 10:37:59 字数 632 浏览 0 评论 0原文

我有一个 CLSID,我需要在我的工作机器(即 MWS )所在的不同服务器(即 DCS )中实例化它。

现在,如果我使用以下内容:

var type = Type.GetTypeFromCLSID(new Guid(CLSID),
       Environment.MachineName, true);
 var COMObject = Activator.CreateInstance(type);
 var returnValue = COMObject.GetType().InvokeMember(methodName,
                        flags, null, COMObject, args, argModifiers, null, null);

然后我收到“COM 目标未实现 IDispatch”错误。好的,我知道 COM 目标对象可能没有 IDispatch,因此失败。

现在尝试其他方法,如果我在 VS 中添加该 COM DLL 的引用,那么 VS 会生成互操作程序集,然后一切都像常规 .net 对象创建一样工作,但在这种情况下,该对象实际上是在我的本地计算机中生成的(MWS pc)没有进入我想要的服务器。

大家有什么建议我该如何处理这种情况?

提前致谢。

I have a CLSID and I need to instantiate this in a Different server (i.e. DCS ) where as my working machine is (i.e. MWS ).

Now, if I use following :

var type = Type.GetTypeFromCLSID(new Guid(CLSID),
       Environment.MachineName, true);
 var COMObject = Activator.CreateInstance(type);
 var returnValue = COMObject.GetType().InvokeMember(methodName,
                        flags, null, COMObject, args, argModifiers, null, null);

Then I get "COM target does not implement IDispatch" error. Ok, I understand that probably the COM target object doesn't have the IDispatch, so it fails.

Now then tried something else, If I add a reference of that COM DLL in VS, then VS generate the interop assemblies and then everything works like regular .net object creation, but in that case the object is actually generating in my local machine (MWS pc) not into the server what I want.

Guys any suggestion how can I deal this situation?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍白女子 2024-10-07 10:37:59

您可以从目标计算机导出 COM+ 作为代理,并将其安装在运行应用程序的计算机上。

转至目标计算机上的组件服务控制台,右键单击 COM+ 应用程序并选择导出...,然后选择应用程序代理单选按钮。这会将代理作为 MSI 文件导出到该 COM+ 应用程序。您需要将其安装在您的计算机上,而不是真正的 COM+ 应用程序(这意味着如果安装在那里,则将其删除),然后尝试您的互操作。

You could export your COM+ from the target machine as a proxy and install it on your machine running the application.

Go to Component Service console on your target machine, right click on your COM+ application and choose Export ... Then select Application Proxy radio button. This will export a proxy to that COM+ application as a MSI file. You need to install it on your machine instead of real COM+ application (that means deleting it if it's installed there) and then try your interop.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文