. NET Remoting learning notes (1) concept, remoting learning notes

Source: Internet
Author: User
Tags configuration settings

. NET Remoting learning notes (1) concept, remoting learning notes
Background

I have heard of this term Remoting since I started programming, But I know little about it. Recently, I have been referring to the research.

This chapter does not explain the relevant concepts, specific you can see the http://baike.baidu.com/view/742675.htm? Fr = aladdin, which is detailed.

. Net Remoting Concept

Concept: a distributed processing method. From the perspective of Microsoft products, it can be said that Remoting is an upgrade of DCOM (Distributed Component Object Mode), which improves many functions and is well integrated into the. Net platform.

Benefits:

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

In Windows, applications are separated into separate processes. This process forms a boundary around the application code and data. If the inter-process communication (RPC) mechanism is not used, the Code executed in one process cannot access another process. This is an operating system's protection mechanism for applications. However, in some cases, We need to cross the application domain and communicate with another application domain, that is, cross the border.

2. Server objects can be published as services:

The code can run on the server (such as the server-activated object and the client-activated object), and then the client connects to the server through Remoting to obtain the service object and serialize it to the client.

3. Loose coupling between client and server objects

In Remoting, in addition to the channel type and port number, the designer does not need to know the data packet format for the objects to be transmitted. This ensures loose coupling between client and server objects, and optimizes communication performance.

 

. NET Remoting supports channels and protocolsThere are two main Remoting channels: Tcp and Http. IChannel includes TcpChannel and HttpChannel.

TcpChannel: The Tcp channel provides a Socket-based transmission tool that uses the Tcp protocol to transmit serialized message streams across the Remoting boundary. The message object is serialized in binary format by default, with higher transmission performance. Applicable to lan.

HttpChannel: It provides an Http protocol for transmitting serialized message streams over the Internet through the firewall. The HttpChannel type serializes message objects in Soap format, so it has better interoperability. Applicable to the World Wide Web.

 

Differences from WCF and WebService

Write here better: http://kb.cnblogs.com/page/50681/

  • Remoting can flexibly define the Protocol Based on, such as http and tcp. If it is defined as HTTP, it is the same as Web Service, but webservice is stateless, remoting is generally used to define TCP, which is a little more efficient and stateful than Web Services.
  • Remoting is not a standard, while Web Service is a standard.
  • Remoting usually needs to be started through a WinForm or Windows Service, or you can deploy it using iis, while Web Service must be started in IIS.
  • In the VS.net development environment, Web Service calls are encapsulated, which is easier to use than Remoting.
  • Net remoting can only be applied to MS. net framework, the client must install the framework, but the WebService is platform independent, cross-language (as long as the language can support XML) and penetrate the Enterprise Firewall.

 

. NET Remoting Activation Method (further details)

Simple understanding: we know that our Remoting application needs to process objects remotely. How are these objects created? Who created it ?... The activation method is to explain these questions.

Remote object activation can be divided into two categories: server-side activation (WellKnow) and client activation.

Two server activation modes are available: SingleTon mode and SingleCall mode. Remoting steps

1. Create a remote processing type (because the objects passed by Remoting are referenced, the passed remote object class must inherit MarshalByRefObject .)

2. Create a server

3. Create a client

MarshalByRefObject

Externalbyrefobject is the base class of objects that communicate across application domain boundaries by Using proxy exchange messages.

Objects not inherited from externalbyrefobject are implicitly sent by value.

When a Remote Application references a value-based object, a copy of the object is transferred across the remote processing boundary.

Because you want to use the proxy method instead of the copy method for communication, you need to inherit MarshallByRefObject.
 
Remote objects that can be passed in Remoting can be of various types, including complex DataSet objects, as long as they can be serialized. Remote objects can also contain events, but server-side processing of events is quite special (for details later ).

 

A simple case Column

1. Write Remote Processing

Using System; using System. runtime. remoting. metadata;/* code interpretation */namespace MessageMarshal {/* create a message sending delegate */public delegate void SendMessageHandler (string messge); public class TestMessageMarshal: export albyrefobject {/* create a message sending event */public static event SendMessageHandler SendMessageEvent;/* send a message */[SoapMethod (XmlNamespace = "MessageMarshal", SoapAction = "MessageMarshal # SendMessage" public void SendMe Ssage (string messge) {if (SendMessageEvent! = Null) SendMessageEvent (messge );}}}

2. Create a server

Using System; using System. runtime. remoting; using System. runtime. remoting. channels; using System. runtime. remoting. channels. http; namespace TestRemotingServer {/* code: Sakya Nakhon */class Program {static void Main (string [] args) {Console. writeLine ("create HTTP channel");/* create HTTP channel */HttpChannel channel = new HttpChannel (816);/* Register channel server */ChannelServices. registerChannel (channel, false);/* register the server and use Singletong to activate */RemotingConfiguration. registerWellKnownServiceType (typeof (MessageMarshal. testMessageMarshal), "TestMessageMarshal", WellKnownObjectMode. singleton);/* receive client events */MessageMarshal. testMessageMarshal. sendMessageEvent + = new MessageMarshal. sendMessageHandler (TestMessageMarshal_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 Releaser */namespace TestRemotingClient {class Program {static void Main (string [] args) {/* Create channel */HttpChannel channel = new HttpChannel (); /* register the channel */ChannelServices. registerChannel (channel, false);/* Registration channel Remote processing type */RemotingConfiguration. registerWellKnownClientType (typeof (MessageMarshal. testMessageMarshal), "http: // localhost: 816/test");/* 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 (2000 );}}}}

4. Test

 

Write it here for now. If you have any questions, please correct them! Subsequent Updates

 

Author: Sakya bitter monk Source: http://www.cnblogs.com/woxpp/p/3992771.html this article copyright belong to the author and blog park a total, welcome to reprint, but without the author's consent must retain this paragraph of the statement, and in the Article Page clearly given the original connection.


The difference between WebService and Remoting in the net Framework

The difference between Web Service and Remoting is as follows:
Web services are divided into five levels:
1. Http Transmission Channel
2. XML data format
3. SOAP Encapsulation Format
4. Description of WSDL
5. UDDI
The Web Service structure in. NET is relatively simple and easy to understand and apply:
Generally, WebService applications in the. NET structure are based on the. net framework and IIS architecture, so it is relatively easy to deploy.
From the implementation perspective,
First, WebService must inherit the class of the method exposed to the client from the base class: System. Web. Services. WebService.
Second, the exposed methods must be preceded by [WebMethod] or [WebMethodAttribute].
Running Mechanism of WebService
First, the client uses the WSDL from the server to the WebService, and claims a Proxy Class on the client)
This proxy class is responsible for Request and Response with the WebService Server
When a data (in XML format) is encapsulated into a data stream in SOAP format and sent to the server, a process object is generated and the SOAP packet that receives the Request is parsed, then, the transaction is processed. After the processing is completed, the computation result is packaged with SOAP, and then the package is used as a Proxy Class sent to the client as a Response. Similarly, this proxy class also parses the SOAP package and then performs subsequent operations.

This is a running process of WebService.

And. net Remoting is:
. Net Remoting is a technology developed on the basis of DCOM. Its main purpose is to achieve cross-platform, cross-language, and penetration of Enterprise Firewall, which is also its basic feature, different from WebService, WebService supports HTTP and TCP channels. It can not only transmit SOAP packets in XML format, but also transmit binary streams in the traditional sense, this makes it more efficient and flexible. In addition, it does not rely on IIS, and users can develop (Development) and deploy their favorite host servers. Therefore, in these aspects, WebService is actually a special case of. net Remoting.

WebService and Remoting are compared as follows:
WebService features Platform-independent, cross-language (any language that supports XML), and enterprise firewall penetration.
However, its disadvantage is that a Web Server needs to be deployed, and the speed is relatively slow;

. Net Remoting features
The advantage is that users can use both TCP-based binary stream communication and HTTP-based SOAP-based communication.
The efficiency is much higher than that of WebService, but its disadvantages are also obvious.. net remoting can only be applied under the. net framework of MS.
In terms of performance, the efficiency of Remoting is very similar to that of traditional DCOM and COM +!

Net Remoting technical issues

. NET remote processing provides an abstract method for inter-process communication, which isolates objects that can be remotely processed from specific client or server application domains and specific communication mechanisms. Therefore, this is flexible and easy to customize. You can use one communication protocol to replace another communication protocol, or use one serialization format to replace another serialization format without re-compiling the client or server. In addition, the remote processing system assumes that there is no special application model. You can use Web applications, console applications, and Windows Services to communicate with almost any program you want. The remote processing server can also be an application domain of any type. Any application can process objects remotely and provide services to any client on its computer or network.
The System. Runtime. Remoting namespace provides classes and interfaces that allow developers to create and configure distributed applications. Some more important classes in the System. Runtime. Remoting namespace are the RemotingConfiguration class, RemotingServices class, And ObjRef class.
The RemotingConfiguration class contains static methods used to connect with configuration settings. The RemotingConfiguration. Configure method allows developers to Configure the remote processing infrastructure by formatting the configuration file in XML. The RemotingConfiguration class also contains several methods for registering the client activation object and the server activation object that reside on the server on the client and the server.
The RemotingServices class provides several methods to help you use and publish remote objects. System. runtime. remoting. remotingServices. the Marshal method provides the ability to store all relevant information required to activate a remote object and communicate with it in an ObjRef instance for future serialization and transmission to a remote location. The System. Runtime. Remoting. RemotingServices. Unmarshal method reverses this process by creating a proxy for remote objects that can be used by applications, regardless of any remote processing branch.
The ObjRef class saves all relevant information required to activate the remote object and communicate with it. This class is a serialized representation of objects transmitted over a channel to a remote location. It is unblocked from being sent over a channel (see Unmarshal) and can be used to create a local proxy for a remote object.

All of the above are MSDN materials. Learn to read MSDN.

Related Article

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.