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
Using system;using system.runtime.remoting.metadata;/*code monk */namespace messagemarshal{/ * Create send Message delegate * / public delegate void Sendmessagehandler (string messge); public class Testmessagemarshal:marshalbyrefobject {/ * Create Send Message Event */public static event Sendmessagehandler sendmessageevent; /* Send Message * /[Soapmethod (XmlNamespace = "Messagemarshal", soapaction = "messagemarshal#sendmessage")] public void SendMessage (String messge) { if (sendmessageevent! = null) sendmessageevent (Messge) ; }}
2. Create a service-side
using system;using system.runtime.remoting;using system.runtime.remoting.channels;using System.runtime.remoting.channels.http;namespace testremotingserver{/*code: Ghana Bitter Monk */class program {static V OID Main (string[] args) {Console.WriteLine ("Create HTTP Channel"); /* Create an HTTP Channel */HttpChannel channel = new HttpChannel (816); /* Register the Channel service side */ChannelServices.RegisterChannel (channel, false); /* Server registration, using Singletong activation */RemotingConfiguration.RegisterWellKnownServiceType (typeof (Messagemarshal.testmessagema Rshal), "Testmessagemarshal", Wellknownobjectmode.singleton); /* Receive client Events */MessageMarshal.TestMessageMarshal.SendMessageEvent + = new Messagemarshal.sendmessagehandler (testmes Sagemarshal_sendmessageevent); Console.read (); } static void Testmessagemarshal_sendmessageevent (String messge) {Console.WriteLine (MESSGE); } }}
3. Create a Client
Using system;using system.runtime.remoting;using system.runtime.remoting.channels;using System.runtime.remoting.channels.http;using System.threading;/*code Buddhist monk */namespace TestRemotingClient{ class Program { static void Main (string[] args) {/ * Create Channel * /HttpChannel channel = new HttpChannel (); /* Register Channel * /ChannelServices.RegisterChannel (channel, false); /* Remote processing type for registered channel */ Remotingconfiguration.registerwellknownclienttype (typeof (Messagemarshal.testmessagemarshal ), "Http://localhost:816/TestMessageMarshal"); /* Create a message entity * /Messagemarshal.testmessagemarshal TestMessage = new Messagemarshal.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 article is copyrighted by the author and the blog Park, Welcome to reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original link.
"Reprint". NET Remoting Learning Notes (i) concept