如何从 C# 调用 DCOM 对象?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从目标计算机导出 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.