Getting started with Microsoft. NET remoting for data communication (2)

Source: Internet
Author: User

The last time I showed you a simple exampleRemotingToday, we are gradually getting familiarRemoting.

FirstRemotingConnect two applications through channelsProgramCommunication between domains, through the clientRemotingAccess Channel to obtain remote objects on the server, and then parse the objects as client objects through proxy. Remote ObjectCodeIt can run on the server (including the objects activated by the server and the objects activated by the client ).RemotingConnect to the server to obtain the service object and run it on the client through serialization

You can register multiple channels at the same time in remoting, but different port numbers and names must be used for identification, because names are unique identifiers of the channel.

I Remote Object

Remote object activation, including client activation and server activation

Server activationCalledWellknowActivation, but many books translate into well-known object activation methods.UriAnd the server process configuresWellknowObjects are published based on the specified address, protocol, and port.

 That isRemotingconfiguration. Registerwellknownservicetype (Typeof (Remotetest),"Proname",Wellknownobjectmode. Singleton );

 Or yes.

Remotingconfiguration. Registerwellknownservicetype (Typeof(Remotetest),"Proname",Wellknownobjectmode.Singlecall);

SinglecallAnd Singleton represent two different modes,

SingletonThis is the state mode. It can be understood that all clients share one object. When it is activated, it processes all client requests at the same time, regardless of whether it is the same client instance.

SinglecallAn object is called the stateless mode,SinglecallIs a stateless mode. Once setSinglecallWhen the client calls the method of the remote object,RemotingCreates a remote object instance for each client.GCAutomatically managed. As we often seeSession.

  Client Activation And Wellknown Different modes, Remoting When activating each object instance, it will assign Uri To the client activation type. Once a client request is obtained, an instance reference is created for each client. In addition, Singlecall The creation time is different from the time when the client activates the object instance. The client activation method is instantiated once the customer sends a call request. Singlecall It is created when the object method is called. Second, Singlecall The objects activated in the mode are stateless, and the object lifecycle management is performed GC Management, while the client-activated objects are stateful, and their lifecycles can be customized. Third, the two activation modes have different implementation methods on the server side and the client side. Especially on the client, Singlecall The mode is composed GetObject () It calls the default constructor of the object. In the client activation mode Createinstance () It can pass parameters, so you can call a custom constructor to create an instance.

There are two methods for activating the client:

1) Call Remotingconfiguration Static Method Registeractivatedclienttype () . The return value of this method is Void It only registers the remote object on the client. The object class constructor must be called for actual instantiation.
Remotingconfiguration. registeractivatedclienttype (
Typeof ( Remotetest )," TCP: // 192.168.168.165: 8081/ Proname ");
  Remotetest Serverobj = new Remotetest ();

2) Call Process Activator Of Createinstance () Method. This method creates class objects of the specified type of method parameters. It corresponds to GetObject () The difference is that it needs to call the constructor on the client, while GetObject () Only get the object, and create an instance on the server side. Createinstance () There are many overload methods. I will focus on some of them.
《 1 " Public static object createinstance (type, object [] ARGs, object [] activationattributes );

ARGs []The passing is actually the parameters of the constructor.

《2"Public static objecthandle createinstance (string assemblyname, string typename, object [] activationattribute );

《3"Public static objecthandle createinstance (type );

《4"Public static objecthandle createinstance (type,Bool nonpulic );

In fact, in daily use, the above just helps you understandRemotingBasic knowledge. In practical applications, if custom objects are transmitted, the correlation with metadata, and the integration of interface knowledge, we need to fully integrate them.

I hope "I threw out a brick, but I can't help it !"

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.