Many applications are based on servers and clients, which can distribute functions to different computers and greatly improve the flexibility of the system. This operation feature is that the client sends a message to the server, and the server returns the result to the client for processing. The. NET platform provides two solutions: WebService and remoting. Remoting provides strong remote object processing capabilities. Based on remoting, you can quickly establish your own message processing framework to facilitate distributed system processing.
(Figure 1)
1. Define the message interface and message processing interface
Before determining the function, you must formulate the specifications to facilitate the work.
Define the message interface rules as simple as possible. Of course, the object cannot be too extensive or express the purpose.
Message rules:
Public interface iMessage
{
String ID
{
Get;
}
String name
{
Get;
Set;
}
Object Body
{
Get;
Set;
}
}
The message rules are clear, and the rules that can process messages must be clear. Without this rule, you cannot work because messages and processed classes can be bound with no information.
Message Processing rules:
Public interface idispense
{
Void accept (iMessage message, servercontext context );
}
2. Create configuration files related to message and Service Processing
This one serves as a bridge, which tells the message processing container to execute those functions for different messages.
You can describe the functions that messages trigger:
<Message blltype = "classname, assembly" msgtype = "classname, assembly" single = "bool"/>
You can also describe all messages in the namespace to trigger those functions.
<Message blltype = "classname, assembly" msgtype = "namespace. *, assembly" single = "bool"/>
Single is used to describe whether to process only one object of an instance or instantiate each message separately.
3. Specify a message distribution processing container
The message processing container is mainly used for management and message distribution. After receiving a message, the server sends it to the container for processing. The Container processes the message based on the type of the message and triggers the corresponding function.
Class 4 Graph