Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   |   Class Browser
  |   I want my samples in...   

How Do I...? Common Tasks QuickStart Tutorial

Go To...

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 Microsoft.Samples.Remoting.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.

C# Passing by Value
View Source

[This sample can be found at M:\web\users\Sites\AspnetQuickStart\v2.0\QuickStart\HowTo\Samples\Remoting\byvalue\
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin directory.]




Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.


Hosted by MaximumASP | Found a broken link? | Contact Us | Terms and conditions | Privacy Policy | Advertise with us
� 2000 - 2008  Mindcracker LLC. All Rights Reserved