如何从C#调用DCOM对象? [英] How to call a DCOM object from C#?

查看:541
本文介绍了如何从C#调用DCOM对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

然后我得到COM目标不实现IDispatch错误。好吧,我明白COM目标对象可能没有IDispatch,所以它失败。

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.

现在尝试其他方法,如果我在VS中添加一个COM DLL的引用,然后VS生成interop程序集,然后一切都像正常的.net对象创建,但在这种情况下,对象实际上是在我的本地机器(MWS pc)中生成,而不是进入服务器我想要的。

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?

提前感谢。

推荐答案

目标机器作为代理,并将其安装在运行应用程序的机器上。

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

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

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.

这篇关于如何从C#调用DCOM对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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