AspNet.sk     Diskusné fóra     Vitajte v QuickStarts     ASP.NET     Silverlight     Ako môžem...? (en)     Class prehliadač Príklady chcem v ...   
Menu
Skip Navigation Links.

How Do I...? Common Tasks QuickStart Tutorial

How Do I...Pass An Object to a Server By Reference?

This example demonstrates how to create an object that derives from MarshalByRefObject on the client that is then passed as a parameter to the server. The server calls a method on the remote object it receives. The first step is to create the object you need to pass.


Imports System
Namespace Microsoft.Samples.Remoting.RemotingSamples

  Public Class ForwardMe : Inherits MarshalByRefObject

        Sub CallMe(String text)
            Console.WriteLine(text)
        End Sub
    End Class
End Namespace
VB

Since the compiler requires the metadata for this object for both the client and server applications, you will compile the class and create a separate assembly for it.


vbc /debug+ /target:library /out:share.dll share.vb
VB

On the server side, because we're passing a custom type (ForwardMe), a custom formatter for the TcpChannel sink chain with TypeFilterLevel set to Full must be used. If we were passing a primitive type instead, TypeFilterLevel could be set to Low. See the Automatic Deserialization in .NET Remoting section of the .NET Framework documentation for more information about deserialization in .NET Remoting.


' creating a custom formatter for your TcpChannel sink chain.
Dim provider As New BinaryServerFormatterSinkProvider()
provider.TypeFilterLevel = TypeFilterLevel.Full
VB

On the client side, you can create an instance of ForwardMe and pass it as a parameter when you call HelloMethod. The only catch in this example is the way you create the TCP channel - you have to give it a port number. This port number should be different from the one you are already using to communicate with the server. When the client channel is registered, the framework will start listening on this port for clients to connect, and establish a connection with the remote object. This allows bi-directional communication between the client and the server where the client forwards parameters to the server on one port and the server forwards parameters to the client using the other port.

When you run the example, the client should print the text "Regards from the server" to the console window.

VB Passing by Reference
View Source

[This sample can be found at H:\Home\WU_000036_efe47225c86ca62f325a01d8519bc002\Webs\aspnet.sk\quickstarts\QuickStartv20\HowTo\Samples\Remoting\byreference\
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.


Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright © 2005 Microsoft Corporation. All rights reserved.
Preklad do slovenského jazyka - Copyright © 2005 - 2007 www.aspnet.sk, www.qsh.sk
Pošlite komentár k tejto stránke
Copyright © 2002 - 2008 Chastia, spol. s r. o., Igor Stanek, Designed by Lacino
Portál je hostovaný na serveroch firmy Quantasoft - www.qsh.sk.