Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Due to external constraints, I have to provide remoting access to the same object through two URI's. Omitting all the remoting configuration (which does seem to set up correctly), the general idea is:
m_RemotedComponent = new RemotedComponent();
RemotingServices.Marshal(m_RemotedComponent, remotingName1);
RemotingServices.Marshal(m_RemotedComponent, remotingName2);

The two connections provide different interfaces that the one component supports.

Regardless of which order the two Marshal statements appear, the first one works and the second one doesn't. Upon connecting to the second URI, I get the error message saying that the object has to derive from MarshalByRefObject. But, since I can always instantiate the first-listed URI successfully, it obviously does derive from that. If I create a second RemotedComponent, I can marshal it successfully to the second URI, so the problem is clearly related to trying to marshal the same object to two URI's.


Is this supposed to be possible? If so, how?

Posted
Comments
John Whitmire 11-Aug-10 15:32pm    
OK, a little more experimenting revealed that I don't need the two URIs after all; I can make it work with just one. This is now just a curiosity question.

1 solution

It definitely is possible, but it requires a lot more code-behind than what you have above. In general, the process is:

1. Create a Hashtable with the properties set (port and name specifically) for each Channel.

2. Create each channel using the hash table. For example you can create two TCPServerChannel's, or one TCPServerChannel an an IPCServerChannel, etc.

3. Call RemotingServices.Marshal(objref, channelName) for each channel you have registered.

I use this frequently in my server/client programs that have a number of modules that communicate across app-domains. Usually I create an IPC channel for exposing an object locally, and a TCP channel for exposing it globally.

Take for example an Alarm event server. The local app can receive events about alarms from a number of modules running on the server, and the client can view or acknowledge the alarms remotely.

The big thing to remember is that one request from one channel can block all activity (local and remote) if your operation takes a long time and is not set up to be asynchronous. You also have to keep in mind about reentrancy and concurency problems (like locking collections when they are modified).
 
Share this answer
 
v2
Comments
John Whitmire 19-Aug-10 17:15pm    
I must be missing something in what you said. This sounds like exactly what I was doing. The config file contains the channel definitions (2 of them, one TCP, one IPC). The two calls to Marshal(object, uri) aren't different from what you show, except that my URIs are not the same as the channel names. Is there something special about that?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900