Problem with event when a component is running on a remote machine.

  • Thread starter Thread starter Paolo Dupont
  • Start date Start date
P

Paolo Dupont

I need to instantiate a component on a remote server. I did it easily.
However, i can not set the handler for the event associated with the class.
I'm able to implement and use events only if the remote server is the local
machine (quite useless ;-) )

// Code

Type dcomType;
Object dcomObj;
MyClass m_instance;
EventInfo evt;

dcomType = Type.GetTypeFromProgID("ProgId", "computerName", false);
dcomObj = Activator.CreateInstance(dcomType);
m_instance = (MyClass) Marshal.CreateWrapperOfType(dcomObj,
typeof(myClass));

evt = m_instance.GetType().GetEvent("MyEvent");
Delegate m_handler = new _IMyClass_myEventEventHandler(MyHandler);
evt.AddEventHandler(m_instance, m_handler);
//Failed with an exception 'System.Reflection.TargetInvocationException'
occurred in mscorlib.dll
//Additional information: Exception has been thrown by the target of an
invocation.

public void MyHandler(void)
{
....
}


The code works fine if the server is on the local machine.
Any advices ??

TIA, Paolo.
 
You are trying to marshall events across not only a process boundary, but a
server boundary, which is why you are having problems. There are a couple of
ways to handle this.

1. Set up serviced components and use COM+ to broker.
2. Set up a web service on the server that is being contacted (trying to
handle the event). Have a listener for this web service that will
effectively "handle the event".

NOTE: by web service, I mean either ASMX or remoting, not just ASMX.

--
Gregory A. Beamer
MPV; MCP: +I, SE, SD, DBA

**********************************************************************
Think outside the box!
**********************************************************************
 
Dear Gregory,

Thanks for your help.
I forgot to mention that the client a standard c# gui and the server an ATL
C++ component. Is there any problems with remoting in that case ? I`m
currently studying remoting.

TIA,
Paolo.
 
Back
Top