How to call a DCOM object from C#?

2019-04-12 16:10发布

问题:

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.



标签: c# com dcom