BizTalk Utilities CV ,   Jobs ,   Code library
 
Go to the front page to continue learning about XML or select below:

Contents

ReBlogger Contents

Previous posts in WSCF/WCF

 
 
Page 4121 of 20224

Passing parameters in .Net Remoting

Blogger : Geekswithblogs.net
All posts : All posts by Geekswithblogs.net
Category : WSCF/WCF
Blogged date : 2008 May 11

It is well known, that in .Net value type parameters are passed by value, and reference type parameters are passed by reference.
I thought(even after a year working with application that extensively uses Remoting)  that .Net Remoting calls do the same. But I was wrong!
Recently I found that a method with custom class parameter  doesn't have one of the properties updated after return, even if it is certainly updated inside the method.

I looked for a few reference articles.
quickstart Remoting Overview is a little bit confusing:
Object passing. All objects created remotely are returned by reference and have to derive from MarshalByRefObject. Objects passed as parameters to a remote method call can be forwarded by value or by reference. The default behavior is pass by value provided the object in question is marked by the custom attribute [Serializable]. Additionally, the object could implement the ISerializable interface, which provides flexibility in how the object should be serialized and deserialized. Objects that are not marshal by reference or marshal by value are not remotable.
 

How to marshal an object to a remote server by value by using Visual C# is more clear:

Because parameter ForwardMe does not inherit from MarshalByRefObject, it is passed by value to the server.

And finally, article  Copying, Cloning, and Marshalling in .NET clarified it:

By default, all objects in .NET (both value- and reference-types) are marshalled by value when sent across the "wire" to a remote AppDomain.To override this default MBV behavior, one can simply derive one's class from System.MarshalByRefObject .

So the Rules for passing parameters in .Net Remoting are the following.

1. Parameter should have attribute [Serializable] or derive from MarshalByRefObject.
(It would be unusual for a class to be both marked with the serializable attribute and extend MarshalByRefObject.)

2. If parameter is serializable, it is passed by value. Changes inside remote methods do not return to the client.

3. If parameter  derive from MarshalByRefObject , it is passed by reference.

4. I am not sure, what happens If you specify modifier ref  for serializable parameter. I hope that it is also passed by reference, but not sure.

I did not have a chance to read, what are WCF rules for passing parameters.


Read comments or post a reply to : Passing parameters in .Net Remoting
Page 4121 of 20224

Newest posts
 

    Email TopXML