The. NET remoting system is designed to simplify the communication between objects in different application domains. Whether on the same computer or not. Similar to web services, but they have their own advantages and are used in different scenarios.
. Net remoting architecture:
The entire architecture is completed through a proxy, which is already done internally, so it seems that there is no proxy. When a user generates a remote instance, a proxy object is created at the remote end (in fact, it can be called a remote copy, because the structure and methods of the proxy object are similar to those of the remote end. Once a user calls a method in the proxy object and the method is valid, the proxy object is sent to the server, after the Server Object is called, the result of the customer request is returned to the customer agent. The pipeline is used to facilitate communication between them, mainly to transport data, package related protocols, and send them to the client. This is the entire process.
Return 4. Call the Server Object
6 | -------------------------- ^ | ----------------------- |
| 1 | 3 sent to |
Client --------------> Generate proxy object --------> Server
| ^ |
| ___ Call the method _____ |__ | __________________ |
2 5 return
. Net remoting provides a lot of services: (just a few of them)
1. object activation and lifecycle Control
2. Responsible for transmitting information and transmitting information from remote applications to communication channels of remote applications
3. Pipeline serialized messages (binary and SOAP) are serialized to convert the object state to a form that can be transmitted.
. NET remote objects can be configured into three different types:
1. Single call object (a single call object, I understand it myself): This object is released immediately after it is called once, and its status is not saved. When a customer method is called, The system creates a new object and then releases it. That is, each call is created and then released.
2. singleeton object (single object) means that all customer requests use one object to serve, and only one object is generated to serve multiple requests.
3. Client-activated object can be understood as a one-to-one relationship, that is, each request creates an object to serve it. In this way, the object state can be saved.
The code for. Net remoting is as follows:
Bytes ----------------------------------------------------------------------------------------------------
// Introduce the required namespace and add the reference system. runtime. remoting and remoteobject
Using system;
Using system. runtime;
Using system. runtime. remoting;
Using system. runtime. remoting. channels;
Using system. runtime. remoting. channels. TCP;
Using remoteobject;
Using system. IO;
Namespace Server
{
Class serverclass
{
Static void main (string [] ARGs)
{
Channelservices. registerchannel (New tcpserverchannel (9999); // listen on port 9999
Remotingconfiguration. registerwellknownservicetype (typeof (remote), "remote", wellknownobjectmode. singlecall); // registers an object of the single call type.
Console. writeline ("the channel has been registered! ");
Console. Readline ();
}
}
}
Bytes ----------------------------------------------------------------------------------------------
// Import required items
Using system;
Using system. runtime;
Using system. runtime. remoting;
Using system. runtime. remoting. channels;
Using system. runtime. remoting. channels. TCP;
Using remoteobject;
Namespace Client
{
/** // <Summary>
/// Summary of class1.
/// </Summary>
Class clientclass
{
Static void main (string [] ARGs)
{
Channelservices. registerchannel (New tcpclientchannel (); // register a channel to communicate with the server
Remote r = (remote) activator. GetObject (typeof (remote), "TCP: // localhost: 9999/remote"); // obtain the remote object with Activator
Console. writeline (R. showdetails ());
Console. writeline ("Welcome to presto systems ");
Console. Readline ();
}
}
}
Bytes ----------------------------------------------------------------------------------------------
Using system;
Namespace remoteobject
{
Public Class Remote: system. externalbyrefobject // inherits marshalbyrefobject to make it a remote object
LIC string showdetails ()
{
Return "all the details are here ";
}
}
}
Bytes ---------------------------------------------------------------------------------------------