Page view counter

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...Create a Client of a Remote Server?

If you haven't already read the section How Do I Create a Remote Server?, please read this first. The client references the server assembly for metadata, so you have to compile the server before the client. The code for the client is listed below.

		
Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.TCP

Namespace Microsoft.Samples.Remoting.RemotingSamples
    Public Class Client
        Shared Sub Main
            Dim obj As HelloServer
            Obj = CType(Activator.GetObject( _
                Type.GetType("RemotingSamples.HelloServer, object"), _
                    "tcp://localhost:8085/SayHello"), _
                HelloServer)
            If obj Is Nothing Then
    	        System.Console.WriteLine("Could not locate server")
    	    Else
    	        Console.WriteLine(obj.HelloMethod("Caveman"))
    	    End If
        End Sub
    End Class
End Namespace
VB

When the client starts up, it registers a TCP channel and proceeds to activate the object by calling the GetObject method on the Activator class. One point to be noted is that, for the client to activate the object the dll should be copied from the Server machine to the client machine. The parameters for this call are as follows:

  1. The type of the name of the class you need to activate, RemotingSamples.HelloServer.

  2. Specify the URI of the object you need to activate. For this client the URI is tcp://localhost:8085/SayHello. Note that the URI includes the protocol, machine name, port number, and the endpoint. If the server is deployed on a host named Sunshine, clients can connect to the server by specifying tcp://sunshine:8085/SayHello.

When you run the client, it locates and connects to the server, retrieves a proxy for the remote object, and calls the HelloMethod on the remote object, passing the string "Caveman" as a parameter. The server returns "Hi there Caveman".

NOTE: All TCP channels use binary serialization when transporting local objects to and from a remote object.

VB Hello Client Sample
View Source

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