These tutorials demonstrate selected features in ASP.NET version 2.0, but they are compatible with later versions of ASP.NET as well. For the current documentation, see the ASP.NET portal on the MSDN Web site.

 

 

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

How Do I...? Common Tasks QuickStart Tutorial

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.

		
Imports System
Namespace Microsoft.Samples.Remoting.RemotingSamples

     Public Class ForwardMe
        Dim mValue As Integer = 1

        Public Sub CallMe()
            mValue += 1
        End Sub

        Public Function getValue() As Integer
            Return mValue
        End Function
    End Class
End Namespace

VB

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
View Source

[This sample can be found at D:\quickstarts.asp.net\QuickStartv20\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.