How to call a DCOM object from C#?

为君一笑 提交于 2019-12-06 11:34:54

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/4105194/how-to-call-a-dcom-object-from-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!