How Do I...Pass An Object to a Server By Value?
The Pass an Object to a Server by Reference section illustrated that local objects are always passed by
value when you call a remote function. To demonstrate this concept, you need change the previous example.
The first step is to create the object you need to pass to the server.
using System;
namespace RemotingSamples {
[serializable]
public class ForwardMe {
private int mValue = 1;
public void CallMe() {
mValue++;
}
public int getValue() {
return mValue;
}
}
}
C#
This class is flagged with the [serializable] custom attribute, which allows it to be
streamed to and from the server. When you run the sample, the client reports the
value of the counter to be one. Since the server calls the CallMe method on
the object five times, the value of the counter when the object is returned
is six. Note that the client has two instances of the ForwardMe class
after calling the remote method: the instance that was passed and a copy of
the instance that was returned.
VB Passing by Value
[This sample can be found at C:\DevFusion.Data\legacy\quickstart.developerfusion.co.uk\QuickStart\HowTo\Samples\Remoting\byvalue\]
Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2004 Microsoft Corporation. All rights reserved.
|