. NET Remoting build distributed database query

Source: Internet
Author: User

Introduction

With the rapid development of traditional databases, computer networks, and digital communication technologies, the research and development of distributed database systems featuring data distributed storage and distribution processing have attracted more and more attention. Microsoft provides two solutions to implement data services for users, namely. NET Remoting and Web Service technologies. As we all know, the Web Service technology is already a recognized standard data transmission solution in the industry. It is based on HTTP and can easily pass through the firewall, while the Remoting technology is in. in the. NET environment, there are several channels for data transmission within the application or between application domains. the appropriate channel can also be used in data transmission. However, in a closed network environment, selecting a TCP channel will achieve better connection performance. In this case, NET Remoting has obvious advantages.

Introduction to Remoting framework

. NET Remoting provides a framework that allows an object to interact with another object through an application domain. This framework provides a variety of services, including activation and storage support, and communication channels responsible for message transmission with remote applications. And ,. NET Remoting is a rich and scalable framework that enables seamless communication between objects distributed across different application domains, processes, and computers. It provides programming models and runtime support, which are powerful and convenient, and can achieve transparent interaction.

Understanding the Remoting framework

1. Basic Principles


Figure 1. NET Remoting Architecture

. NET Remoting implements object communication between two application domains through channels. There are two main Remoting channels: Tcp and Http. In. NET, the IChannel interface is defined in System. Runtime. Remoting. Channel. The IChannel interface includes the TcpChannel and Http channel types. They correspond to the two types of Remoting channels respectively. The channel object represents the connection to a remote application. Each channel object also contains a formatting program object that converts a method call to a message in a known format.

The basic principle 1 is shown. First, the client accesses the server object through the channel to obtain the proxy of the server object. A server object, also known as a remote object, is used as a proxy to obtain the remote object by passing object references across application boundaries. For a client program, the proxy provides the same methods and attributes as remote objects. When you call different methods, messages are created. By using the formatting program class, these messages are serialized and sent to the customer channel. The customer channel communicates with the server channel to transmit messages over the network. The server channel uses the formatter to parallelize messages and send the methods to remote objects. Through proxy, client applications can operate remote objects just like local objects.

2. Application domain

In Windows, applications are separated into separate processes to form the Protection Boundary of application code and data. Although processes are effective in isolating applications, they also have disadvantages: first, processes belong to a low-level operating system structure, and management processes involve many operating system behaviors; creating and managing processes is a very expensive task. Without Interprocess Communication (IPC), the code executed in one process cannot access another process, the additional overhead of the IPC Mechanism often outweighs the final gain. In many cases, we need an object to cross the application domain and interact with another object .. The application domain introduced by NET solves the above problems. The application domain is the logical process representation of the. NET Runtime Library. Any actual operating system process can contain multiple application domains. Application domains have the following advantages:

  • Hides the specific operating system information of a process.
  • Application domains also provide isolation, and all. NET objects are defined in the application domains where they are created.
  • For processes that do not require an expensive IPC Mechanism, the application domain allows the. NET Runtime Library to optimize communications between applications running in it.

3. Remote Object Activation Method

The remote object is derived from the System. externalbyrefobject class. before accessing an object instance of the remote type, it must be created and initialized through a process named Activation. This kind of client creates a remote object through a channel is called the activation of the remote object. In Remoting, the activation of remote objects falls into two categories:

  • Server-side activation: Also known as the WellKnown method. Objects activated in this way are called server-side activation objects or well-known objects. This is because the server-side application will publish this type through a well-known Uniform Resource Identifier (URI) before activating the object instance .. Net Remoting divides server activation into Singleton mode and SingleCall mode. In Singleton mode, the runtime creates only one object to accept all client requests, and uses the lease policy to control its lifetime. In SingleCall mode, the runtime creates a new object for each client request, releases the object after the request is completed, and is destroyed by the garbage collector (GC.
  • Client activation: In this mode, once the server receives a request from the client, an instance reference is created for each client. Although this mode is similar to the SingleCall mode activated on the server, they are different: first, the objects activated in SingleCall mode are stateless, the GC is responsible for object lifecycle management, while the client-activated objects are stateful and can be customized. Second, the SingleCall mode creates an object instance when the object method is called, the client activation method is instantiated when the customer sends a call request. Third, in SingleCall mode, only the default constructor of the object can be called, you cannot call a custom constructor to create an object instance by passing parameters. In client activation mode, you can call a custom constructor to create an instance.

4. Configuration File

In addition to publishing remote objects through programming, you can also use the configuration file to configure the server-side applications. The configuration file has the following advantages:

  • You can configure channels and remote objects without modifying any code, and do not need to re-compile the application.
  • This greatly reduces the Code required to implement remote objects.

The following is a configuration file on the server that activates remote objects in SingCall mode (named DbServer.exe. config ):

<Configuration>
<System. runtime. remoting>
<Application>
<Service>
<Wellknown mode = "SingleCall"
Type = "DbServerLibrary. DbServer, DbServerLibrary"
ObjectUri = "DbServer"/>

</Service>
<Channels>
<Channel ref = "tcp" port = "8888"/>
</Channels>
</Application>
</System. runtime. remoting>
</Configuration>

In the client activation mode, change wellknown to activated and delete the mode attribute. Then, you only need to use the following line of code to publish remote objects:

RemotingConfiguration. Configure ("DbServer.exe. config ");

Similarly, the client can use a configuration file to obtain remote object references. After using the preceding line of code, you only need to simply use the new operator (other methods can be used) you can operate remote objects like local objects. It can be seen that. NET Remoting provides users with a flexible and convenient way to publish and obtain remote objects, and provides convenient application deployment solutions.

System implementation and related technologies

1. Distributed Database

A Distributed Database is a set of structured data logically belonging to the same system but physically distributed across different nodes in a computer network. Compared with a centralized database, it has the following main advantages: it can solve the problem that organizations are scattered and data needs to be interconnected; load balancing -- can avoid critical bottlenecks; high reliability -- faults occur in individual sites, it will not paralyze the entire system; it has good scalability-it can be expanded with minimal impact on the current organization.

The core issue in distributed databases is how to determine the data distribution solutions for each site in the computer network, including data distribution, segmentation, and Redundancy Design. The system uses a distributed scheme combining horizontal sharding and induced sharding. Data integrity is limited by the relationship between tables, and error messages are reported to users by capturing exceptions in programs.

2. ADO. NET

Distributed Database technology has many advantages, but it also brings new problems, such as data consistency, remote data transfer implementation, and reduced communication overhead, this makes the development of distributed database systems more complex. An ideal solution to solve these problems is to use the ADO. NET data access model provided by the. NET Framework. ADO. NET uses optimistic consistency solutions to control data consistency and can respond to a large number of users in less time. The combination of these two technologies greatly simplifies the workload and difficulty of developing distributed database systems.

3. implement, publish, and obtain remote objects

First, declare a remote object class derived from the externalbyrefobject class in the class library, which defines the services required for remote calls, such as data query, table connection, and merge. Use ADO. NET's powerful functions can easily implement a variety of data services, especially it provides optimization support for SQL server. If the underlying database uses SQL SERVER, it will obtain better performance than other database systems. Then, the remote object class is encapsulated as a dll through the dynamic link library technology, and then distributed to each site.

When a remote object is published on the server, you must first set a port number, create and register a channel, and then publish the activation object on the server. Servers in other sites can conveniently obtain published remote objects based on their IP addresses and network port numbers. The key code for remote object publishing and retrieval is as follows:

Remote Object publishing:

TcpChannel chan = new tcpchannels (8888 );
ChannelServices. RegisterChannel (chan );
RemotingConfiguration. RegisterWellKnownServiceType (typeof (DbServerLibrary. DbServer), "DbServer ",
WellKnownObjectMode. Singleton); // publish the server activation object in Singleton mode.

Remote Object acquisition:

DbServer = (DbServerLibrary. DbServer) Activator. GetObject (typeof (DbServerLibrary. DbServer ),
"Tcp: /219.224.xx.xx: 8888/DbServer ");

4. Application Deployment

After remote objects are implemented, you can deploy applications in multiple ways. For example, you can deploy the remote object assembly (DbServerLibrary) of each server. to enhance security, you can also deploy metadata assembly or interface dataset to achieve the same implementation. In this system implementation, metadata assembly is deployed and the following simulation is performed: the same machine simulates a server and a local client by using different database files. In this way, the system can be tested on two machines.

After the system starts, first start the server applications at each site and receive requests from the client through the registered port. After obtaining the user query request, the client first uses the SQL command parsing module, queries the data dictionary, splits and restructured the command, and then initializes the remote object proxy, assign the command to the remote object proxy, call the remote object method, return the result set, and display the result set on the interface to complete the user request.

Summary

Distributed applications are widely studied and applied for their high scalability and scalability, and resource sharing improves the system cost effectiveness, various distributed computing objects and platforms have also been extended and expanded .. NET Remoting is. the NET Framework provides a powerful technology that enables applications located anywhere to communicate with each other. These applications may run on the same computer, or different computers in the LAN may also be located in a network with a huge difference of thousands of miles.

The use of. NET Remoting technology combined with ADO. NET can efficiently and reliably build distributed data application solutions. Its advantage is that it can be used. NET Remoting framework can easily solve the problem of remote transmission of data and commands.. NET allows convenient operations on databases, making the distributed database system more efficient and reliable, and easy to solve data integrity and consistency problems.

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.