The release number of this article has been CHS307739
For Microsoft Visual Basic .NET versions of this article, see
300943.
This task content
summary
Requires how to create a client reference access to the remote server
SUMMARY This step-by-step guide demonstrates how to create a client accessing the remote server. This client can be located on the same computer, different computers or different networks. This article is written on the basis of the following Microsoft Knowledge Base articles:
307445 Create a Remote Server Using Microsoft Visual C # .NET (using Microsoft Visual C # .NET Create Remote Server)
Back to top
The following table summarizes the recommended hardware, software, network architecture, and service pack required:
Microsoft Visual Studio .NET This article assumes that you are familiar with the following topics:
The Visual Studio .NET network must be used first before the steps in this article (see
Introduction in 307445).
Back to top
How to create a client accessing the remote server
Create a console application in Visual C # .NET. Class1 is created by default. Rename Class1.cs is reamerled to clientapp.cs. Add a reference to the project to the System.Runtime.Remoting namespace. Add a reference to the ServerClass.dll assembly (created in 307445). Clients can use three different ways to reference remote objects and parses each reference for each reference. This example uses the first method (a).
Compile the server object and specify the .exe or .dll file as a compiler reference when compiling the client. This method is very useful when the client and server component is developed at the same site. Delicate the server object from an interface class and compile the client using the interface. This method is very useful when the client and server components are not developed on the same site. This (these) interfaces can be compiled as a dynamic link library (DLL), which can be sent to the client site when necessary. Do not change the published interface as much as possible. Use the SOAPSUDS tool to extract the required metadata from the running server object. This method can be used when the client and server components are developed at different sites, and the interface class cannot be used. Point the SOAPSUDS tool to a remote unified resource identifier (URI) and generate the desired metadata as a source or DLL. Remember that the SOAPSUDS tool only extracts metadata; it does not generate a source for remote objects. Use the uses subscripted statement for remoting, remoting.channels.tcp namespaces and ServerClass class names, so that there is no need to define declarations in these namespaces in later code. The USING statement must be before all other statements. Using system;
Using system.runtime.remoting;
Using system.runtime.remoting.channels;
Using system.runtime.remoting.channels.tcp;
USING ServerClass; Declare a variable to initialize the client to connect to the TCPChannel object of the server application. Register the channel to the channel service using the RegisterChannel method. Add the following declaration code during the main MAIN of Class1: TCPChannel CHAN = New TCPChannel ();
ChannelServices.RegisterChannel (CHAN); statement and instantiate remote server. In this example, instantiate the MyRemoteClass object using the getObject method of the ACTIVator object and specify the following parameters: The full type name of the object being registered (this example is ServerClass.myremoteClass, followed by the assembly name serverclass. The name and class name of the namespace are specified here. Because no namespace specified in the previous section, the default root namespace is used. Activate the URI of the object. The URI must contain the protocol (TCP), computer name (localhost), port (8085), and REMOTETEST) of the server object. To access the ServerClass remote server located on the local server, use the URI "TCP: // LocalHost: 8085 / Remotetest". MyRemoteClass Obj = (MyRemoteClass) Activator.getObject (TypeOf (MyRemoteClass),
"TCP: // localhost: 8085 / transtetest");
IF (Obj == Null)
System.Console.writeline ("Could Not Locate Server");
Else
IF (Obj.SetString ("Sending String To Server"))
System.Console.writeline ("Success: Check The Other console to verify.");
Else
System.Console.writeline ("Sending The Test String Has Failed."); Keeps the client application's run using the Readline method of the Console object. System.console.writeline ("Hit
System.console.readline (); Generate your project. Make sure the server application is running. (This is an Exe file created in 307445.) Running the project and test communication between the client and the server.
Back to top
For an overview of .NET remote processing, see the Microsoft .NET Framework Developer Guide.
related
For more information on the TCPChannel class, see the .NET Framework Class Library Document.
For more information on Microsoft .NET remote processing, see the following BETA 1.NET development (General) Technical article:
"Introduction to the Microsoft .NET Remoting Framework" "Microsoft .NET Remoting: a Technical Overview" (Microsoft .NET Remote Processing: Technical Overview)
Activator.getObject and
For more information on the Type.gettype method, see the .NET Framework Class library document.
Back to top
The information in this article applies to:
Microsoft Visual C # .NET Beta 2
Recent Update: 2001-11-5 (1.0) Keyword Kbhowto KbhowTomaster KB307739 KBAUDDEVELOPER