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

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.
 
C

Cowboy \(Gregory A Beamer\)

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!
**********************************************************************
 
P

Paolo Dupont

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top