. NET Remoting Learning Notes (i) concepts

Source: Internet
Author: User

Catalogue
    • . NET Remoting Learning Notes (i) concepts
    • . NET Remoting Learning Notes (ii) how to activate
    • . NET Remoting Learning Note (c) channel
background

Since the contact programming, has been heard this noun remoting, but to his understanding of less, recently a little time, reference research.

The related concepts of this chapter do not elaborate, specific people can look at the Http://baike.baidu.com/view/742675.htm?fr=aladdin, written in very detailed.

. Net Remoting Concepts

Concept: a distributed processing method. From the Microsoft product point of view, it can be said that remoting is a DCOM (Distributed Component Object mode) an upgrade, it improved a lot of features, and excellent integration. NET platform.

Benefits:

1. Provides a framework that allows an object to interact with another object through an application domain.

In the Windows operating system, it is the separation of applications into separate processes. This process forms a boundary around the application code and data. If you do not adopt the interprocess communication (RPC) mechanism, code executing in one process cannot access another process. This is an operating system protection mechanism for applications. In some cases, however, we need to cross the application domain and communicate with another application domain, that is, crossing the boundary.

2. You can publish server objects in a way that is serviced:

The code can run on the server (such as server-activated objects and client-activated objects), and the client then connects to the server via remoting, obtains the service object, and runs on the client through serialization.

3. Loose coupling of client and server-related objects

In remoting, for objects to be passed, the designer does not need to know the format of the packet in addition to the type and port number of the channel. This ensures loose coupling between the client and server-side objects, while optimizing the performance of the communication.

. NET Remoting support channels and protocols

There are two main channels for remoting: TCP and Http,ichannel contain Tcpchannel,httpchannel

TcpChannel: The TCP channel provides a socket-based transport tool that uses the TCP protocol to transmit serialized message flows across the remoting boundary. The default is to serialize the message object using binary format, which has higher transmission performance. applicable local Area network.

HttpChannel: It provides a way to use the HTTP protocol to transmit a serialized message flow over the Internet through a firewall. The HttpChannel type serializes the message object using SOAP format, so it has better interoperability. Applicable to the World Wide Web.

differs from WCF, WebService

It's better to write here: http://kb.cnblogs.com/page/50681/

    • Remoting can flexibly define the protocol on which it is based, such as HTTP,TCP, if it is defined as HTTP, the same as the Web service, but WebService is stateless, and using remoting generally likes to be defined as TCP, which is more than the web The service is somewhat more efficient and stateful.
    • Remoting is not a standard, and Web service is standard.
    • Remoting typically needs to be started with a WinForm or Windows service, or it can be deployed using IIS, and Web service must be started in IIS.
    • In the Vs.net development environment, the invocation of the Web service is encapsulated, which is easier to use than the remoting.
    • NET remoting can only be applied to the. NET framework of MS, requires the client to install the framework, but the webservice is platform independent, cross-language (as long as XML-capable languages are available) and penetrate the corporate firewall.
. NET Remoting Activation Mode

Simple comprehension: We know that in our remoting applications we need remoting objects, so how are these objects created? Who's going to create it? ... And the way to activate it is to explain these questions.

The activation of remote objects falls into two main categories: server-side activation (WELLKNOW) and client activation.

There are two modes of server-side activation: Singleton mode and SingleCall.

Implementing Remoting Steps

1. Create a remoting type (because the object passed by remoting is referenced, the remote object class passed must inherit MarshalByRefObject. )

2. Create a service-side

3. Create a Client

MarshalByRefObject

MarshalByRefObject is the base class for objects that communicate across application domain boundaries by using proxies to exchange messages.

Objects that are not inherited from MarshalByRefObject are implicitly marshaled by value.

When a remote application references an object that is marshaled by value, a copy of the object is passed across the remoting boundary.

Because you want to communicate using a proxy method instead of a copy method, you need to inherit marshallbyrefobject.
The remote objects that can be passed in remoting may be of various types, including complex dataset objects, as long as it can be serialized. Remote objects can also contain events, but server-side handling of events is special.

a simple case list.

1. Writing Remote processing classes

usingSystem;usingSystem.Runtime.Remoting.Metadata;/*code to release the bitter monk*/namespacemessagemarshal{/*Create a Send message delegate*/     Public Delegate voidSendmessagehandler (stringMessge);  Public classTestmessagemarshal:marshalbyrefobject {/*Create a Send message event*/         Public Static EventSendmessagehandler sendmessageevent; /*Send Message*/[Soapmethod (XmlNamespace="Messagemarshal", SOAPAction ="Messagemarshal#sendmessage")]          Public voidSendMessage (stringMessge) {            if(Sendmessageevent! =NULL) sendmessageevent (MESSGE); }    }}

2. Create a service-side

usingSystem;usingSystem.Runtime.Remoting;usingSystem.Runtime.Remoting.Channels;usingSystem.Runtime.Remoting.Channels.Http;namespacetestremotingserver{/*code: The Buddha of the bitter monk*/    classProgram {Static voidMain (string[] args) {Console.WriteLine ("creating an HTTP channel"); /*creating an HTTP channel*/HttpChannel Channel=NewHttpChannel (816); /*Register channel service side*/ChannelServices.RegisterChannel (channel,false); /*server-side registration, activation with Singletong*/RemotingConfiguration.RegisterWellKnownServiceType (typeof(Messagemarshal.testmessagemarshal),"Testmessagemarshal", Wellknownobjectmode.singleton); /*Receiving client Events*/MessageMarshal.TestMessageMarshal.SendMessageEvent+=NewMessagemarshal.sendmessagehandler (testmessagemarshal_sendmessageevent);         Console.read (); }         Static voidTestmessagemarshal_sendmessageevent (stringMessge)        {Console.WriteLine (MESSGE); }     }}

3. Create a Client

usingSystem;usingSystem.Runtime.Remoting;usingSystem.Runtime.Remoting.Channels;usingSystem.Runtime.Remoting.Channels.Http;usingSystem.Threading;/*code to release the bitter monk*/namespacetestremotingclient{classProgram {Static voidMain (string[] args) {            /*Create a channel*/HttpChannel Channel=NewHttpChannel (); /*Register Channel*/ChannelServices.RegisterChannel (channel,false); /*Remote processing type for registered channels*/Remotingconfiguration.registerwellknownclienttype (typeof(Messagemarshal.testmessagemarshal),"http://localhost:816/test"); 
            Here is a small error, which should be:
            Remotingconfiguration.registerwellknownclienttype (typeof"http://localhost:816/ Testmessagemarshal"
/*Create a message entity*/Messagemarshal.testmessagemarshal TestMessage=NewMessagemarshal.testmessagemarshal ();  while(true) {testmessage.sendmessage ("DateTime.Now:"+System.DateTime.Now.ToString ()); Console.WriteLine ("Send Message ..."); Thread.Sleep ( -); }        }    }}

4. Testing

Write here for the time being, if you have any questions please correct me! Follow up to update

The source of the Buddhist monk: http://www.cnblogs.com/woxpp/p/3992771.html This copyright belongs to the author and the blog Park is shared, welcome reprint, but without the author's consent must retain this paragraph, and in the article page obvious location to the original link.

Note: In the project reference you need to add a reference to the System.Runtime.Remoting assembly, and the client and server are added to the Messagemarshal assembly.

. NET Remoting Learning Notes (i) concepts

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.