Build a application that uses the .NET remote processing framework to communicate between the application domain. You must implement remote type (REMOTABLE TYPE) to listen to the requested service application domain and customer application domain. At the same time, you must configure remote processing systems for each application domain so that remote activation is activated to activate the remote type. First, create a remote type: In order to enable objects in other application domains to use your class instance, your class must derive from the System.MarshalByrefObject class. The following code shows how to create a remote class: [Visual Basic] 'RemotableType.vbimports System
Public Class RemotableType Inherits MarshalByRefObject Private _internalString As String = "This is the RemotableType." Public Function StringMethod () As String Return _internalString End Function 'StringMethodEnd Class' RemotableType [C #] // RemotableType.csusing System; public class RemotableType: MarshalByRefObject {private String _internalstring = "this is the remotable page"; PUBLIC STRING STRINGMETHOD () {return _internalstring;}} In order to use the command line tool included with the .NET Framework SDK to compile the classes in the previous example into library files, as long as it is saved as RemotableType.Language-Extension (here Language-Extension is the language you are using, such as CS, VB). Use the following command: [Visual Basic] VBC / T: Library RemotableType.vb
[C #] CSC / Noconfig / T: library remotableType.cs
Second, create a service application (Host Application): To create an instance of a remote object in different application domains, you must create a service application to complete two tasks: (1) Select and register a channel. This channel is an object that handles network protocols and serialization formats. (2) Register your created remote type in the .NET Remoting System, so that the remote system can use your channel to listen to various requests for your remote type. The .NET framework has two default channels: System.Runtime.Remoting.Channels.http.httpchannel (using SOAP format) and system.Runtime.Reming.Channels.tcp.tcpchannel (using binary format). In some cases, HTTPChannel can pass the firewall without opening the port (port), and its supporting standard security and authentication protocols. You can create monitors applications using any type of application (Windows Forms application, ASP.NET web application, console application, Windows service, and other managed applications). Because the remote configuration is based on each application domain, the application field must perform request monitoring. "Note" is different from COM, and the remote processing framework will not start listening applications or server applications for you. The remote configuration can be implemented in the programming phase, or you can use the application or machine configuration file. Using the configuration file allows you to change the remote processing configuration without recompiling your executable. See the following code: [Visual Basic] 'Listener.vbImports SystemImports System.Runtime.RemotingPublic Class Listener Public Shared Sub Main () RemotingConfiguration.Configure ( "Listener.exe.config") Console.WriteLine ( "Listening for requests Press Enter to. Exit ... ") console.readline () End sub'mand Class' Listener [C #] // listener.csusing system; using system.Runtime.Remoting;
Public class listener {public static void main () {transole.exe.config ("listener.exe.config"; console.writeline ("Listening for Requests. Press Enter to EXIT ..."); console.readline ();} } In order to use the command line tool included with the .NET Framework SDK to record the above class into the listener, as long as it is saved as listener.language-extension (here, Language-Extension is the language you are using, such as CS , VB). Save the file to the same directory of RemotableType.dll. Use the following command: [Visual Basic] VBC /R: RemotableType.dll Listener.vb [C #] CSC / Noconfig /R: RemotablePe.dll Listener.cs
The Listener class must be able to find the listener.exe.config file to load the configuration for the RemotableType class. This configuration file must be saved in the same directory as listener.exe. If you don't find it, you will have an exception. The following is a description of the configuration file Listener.exe.config:
Third, create a customer application: The client application must be registered. The remote processing system will intercept the call of the client, and send the call to the remote object and return the result to the client. The code for the customer is as follows: [Visual Basic] 'Client.vb Imports Systemimports System.Runtime.Remoting
Public Class Client Public Shared Sub Main () RemotingConfiguration.Configure ( "Client.exe.config") Dim remoteObject As New RemotableType () Console.WriteLine (remoteObject.StringMethod ()) End Sub 'MainEnd Class' Client [C #] // Client.cs Using System; Using System.Runtime.Remoting; Public Class Client {
public static void Main () {RemotingConfiguration.Configure ( "Client.exe.config"); RemotableType remoteObject = new RemotableType (); Console.WriteLine (remoteObject.StringMethod ());}} to be compiled to produce the corresponding client executable File, just save it as Client.Language-Extension (here Language-Extension is the language you are using, such as CS, VB). Save the file to the same directory of RemotableType.dll. Use the following command to compile: [Visual Basic] VBC /R: RemotableType.dll Client.vb
[C #] csc / noconfig /r :RemotableType.dll Client.cs
As you can see, the Client class must be able to find the client.exe.config file to load the configuration for the RemotableType class. This profile must be saved in the same directory as the client.exe. If you don't find it, you will have an exception. The following is a description of the configuration file Client.exe.config:
Fourth, compile and execute the entire application: Save all the files built in front to a directory named listener, and use the following command line: Visual Basic] VBC / T: library remotableType.vb
VBC /R: RemotableType.dll Listener.vb
VBC /R: RemotableType.dll Client.vb
[C #] csc / noconfig / t: library remote remotablepe.cscsc / noconfig /R :RemotableType.dll listener.cs
CSC / NOCONFIG /R: RemotableType.dll Client.cs
Run the application: 1. Create a subdirectory named Client 2, copy the remoTableType.dll, Client.exe and Client.exe.config to the client directory 3, in the listener directory, use the following command: listener4, when the Listener program Open a new Command window in the client directory and type: Client
Change the channel: The channel can be changed as long as the listner.exe.config and client.exe.config files are modified. The client.exe.config file is modified as follows:
The following modifications in the listener.exe.config file:
"Note" This article is limited to .NET Framework 1.x.