Serializable object containg MarshalByRefObject Object

N

nick_tucker

If I have an Arraylist(which is marked as serailizable) which contains
objects derived from MarshalByRefObject something like below

public class MyArray
{
private ArrayList m_al;

public void MyArray()
{
m_al.Add(MyObject("XXX"));
m_al.Add(MyObject("YYY"));
m_al.Add(MyObject("ZZZ"));
}
public ArrayList AL{get{return m_al;}}
}

public class MyObject:MarshalByRefObject
{
private string m_Data;
public MyObject(string sData)
{
m_Data = sData;
}
public string Data{get{return m_Data;}}
}

When I do the following on the client:

ArrayList alRemotedArrayList = <Get ArrayList from server Via Remoting>
foreach(MyObject obj in alRemotedArrayList)
{
Console.WriteLine(obj.Data);
}

Am I correct in thinking that for each call of 'obj.Data' I am making a
call to the server. And that alRemotedObjects is a collection of
Proxies pointing to the object on the server???

Thanks,
Nick
 
N

Nicholas Paldino [.NET/C# MVP]

Nick,

Yep, that's pretty much how it works. That's the whole point of
MarshalByRefObject, when you access it across app-domain boundaries, a proxy
is created on the client side to make calls to the server.

Hope this helps.
 
G

Guest

Am I correct in thinking that instances of MyObject exist on the server and
that MyArray is built on the client?

If so... then yes, each call to obj.Data requires a round trip to the server
and that alRemotedObjects is nothing but proxies, provided that you have
setup remoting for either instances of MyObject (ie
RegisterWellKnownClientType on the client) or for the contents of MyArray to
exist on the server.

Brendan
 

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

Top