O'Reilly logo

Object-Oriented Programming with Visual Basic .NET by J.P. Hamilton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

9.6. Marshal by Value (MBV)

Example 9-11 contains yet another version of ServerInfo. There are only two differences between this version and the last:

  • The class is marked <Serializable> instead of derived from MarshalByRefObj, which is required to marshal an object by value.

  • All data that is provided by the class is obtained in the constructor instead of at call time.

When ServerInfoFactory.CreateServerInfo is called, all remote machine properties are ascertained immediately. This is necessary because next, the entire class is marshaled by value back to the client; that is, a complete copy is transferred to the client. If the machine values were not obtained in the constructor, the class would return values relative to the client machine (because the object will be local to the client).

Example 9-11 is not meant to be presented as the optimal method for the ServerInfo case. The purpose is to demonstrate the flexibility of the remoting framework and to present some of the issues that are faced in real-world development. Remember, when remoting, use what works and is really fast.

Example 9-11. MBV version of ServerInfo
<Serializable( )> _ Public Class ServerInfo Implements IServerInfo Private machineTime As DateTime Private processorUsed As Single Private availableMemory As Long Private machine As String Private ip As IPAddress Public Sub New( ) 'Get machine info when object ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required