I am very confused with [Serializable] and :MarshalByRefObject attribute in .NET Remoting .However i read many article on that. If i am using [Serializable] attribute then all methods are executed entirely in callers domain, it means that different callers should have copy of different methods on their own domain and any alteration done by one caller should not reflect on others.But when the same thing i am implementing in my program, i am not getting the desired result.
MarshalByRefObject is the base class for objects that communicate across application domain boundaries by exchanging messages using a proxy. Objects that do not inherit from MarshalByRefObject are implicitly marshal by value.
Marshal by Reference: In this type proxy is created by the reference of the server objects. Class must extend the System. MarshalByRefObject to implement marshal by reference. Here, client keeps server object reference which means round trip to server with each method call.
Serializable
attribute is used to sign an object that when it is requested through remoting, it will be serialized to a byte array, transferred as byte array from source to destination and then another instance of object is rebuild from that byte array that lives and breathes in destination environment (AppDomain or Application). Manipulations performed on that object is not reflected to the source. To update object you have to make another trip to the source and send your changed object (as a new byte array of course). it is just like downloading a file and modifying it, your changes are not reflected to the server where you have downloaded file from.
var user = server.GetUser("edokan");
user.Alias = "edokan2";
var user2 = server.GetUser("edokan");
//user.Alias == user2.Alias; // is false
On the other hand MarshalByRefObject
marks your object that instead of data of your object, a reference to your object is traveled through remoting and every method call/every property manipulation is performed on server side. This is just like posting your question to StackOverflow and reading answers, you have nothing but a browser and a url to view/manipulate question. Everything is performed on StackOverflow servers.
Your confusion arises from a very simple point, MS made remoting sooo simple, one actually thinks that everything is on client side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With