c/S architecture application, the transfer of some complex computational logic from the client to the server side can improve performance, but also for other aspects of control.. NET remoting performance is pretty good in LAN calls. The ERP system builds an application server (application Server) based on. NET Remoting and WCF.
Distributed Application design goals:
1 The client connection, the server should be able to control. The server controls the number of client concurrency based on the contents of the licensing file.
2 The server crashes, the client is notified, suspends the current data entry operation, and the client can automatically reconnect when the server is available.
3 Data encryption is supported, encrypted ports and channels can be transmitted to sensitive data.
4 Support data compression, improve data transmission efficiency, because to do a compression and decompression action, performance has been reduced.
5 security control, the application server blocks the connection of an unauthorized or unsigned application.
6 Client transfers large files to the server and optimizes performance when transferring pictures
7 when a server-side discovery error occurs, the support stack passes back to the client to diagnose the cause.
8 easy to develop and deploy.
The interface code for the server to communicate with the client is first designed, and a simple Sales contract data table is shown below.
Public Interface Isalescontractmanager {salescontractentity getsalescontract (Guid sessionId, String contractno); Salescontractentity getsalescontract (Guid sessionId, String Contractno, IPrefetchPath2 Prefetchpath); Salescontractentity getsalescontract (Guid sessionId, String Contractno, IPrefetchPath2 Prefetchpath, Excludeincludefieldslist fieldlist); Entitycollection getsalescontractcollection (Guid sessionId, Irelationpredicatebucket filterbucket); Entitycollection getsalescontractcollection (Guid sessionId, Irelationpredicatebucket filterbucket, ISortExpression SortExpression); Entitycollection getsalescontractcollection (Guid sessionId, Irelationpredicatebucket filterbucket, ISortExpression SortExpression, IPrefetchPath2 Prefetchpath); Entitycollection getsalescontractcollection (Guid sessionId, Irelationpredicatebucket filterbucket, ISortExpression SortExpression, IPrefetchPath2 Prefetchpath, excludeincludefieldslist fieldlist); SalescontractEntity savesalescontract (Guid sessionId, salescontractentity salescontractentity); Salescontractentity savesalescontract (Guid sessionId, salescontractentity salescontractentity, entitycollection Entitiestodelete); Salescontractentity savesalescontract (Guid sessionId, salescontractentity salescontractentity, entitycollection Entitiestodelete,stringSeriescode);voidDeletesalescontract (Guid sessionId, salescontractentity salescontractentity);BOOLIssalescontractexist (Guid sessionId, String contractno);BOOLIssalescontractexist (Guid sessionId, Irelationpredicatebucket filterbucket);intGetsalescontractcount (Guid sessionId, Irelationpredicatebucket filterbucket); Salescontractentity clonesalescontract (Guid sessionId, String contractno);voidPostsalescontract (Guid sessionId, String contractno);voidPostsalescontract (Guid sessionId, salescontractentity salescontractentity); }
The redesign service implements the Salescontractmanager and implements the above interface.
[Communicationservice ( "Salescontractmanager" )] public class Salescontractmanager:managerbase, Isalescontractmanager {public SalesContractEntity Getsalescontract (Guid sessionId, String contractno) {return getsalescontract (SessionId, Contractno, null ); } public salescontractentity getsalescontract (Guid sessionId, String Contractno, iprefetc HPath2 prefetchpath) {return getsalescontract (sessionId, Contractno, prefetch Path, null ); }
Notice that the Communicationservice attribute is added to the above implementation class, which means that the declaration implementation class is a service.
Let's review the simplest. NET Remoting client and server-side code design patterns.
Server-Side design:
int port = Convert.ToInt32 (configurationmanager.appsettings[< span class= "str" > "Port" ]); BinaryServerFormatterSinkProvider Provider = new binaryserverformattersinkprovider (); Provider. TypeFilterLevel = typefilterlevel.full;idictionary props = new Hashtable ();p Rops[ "port" ] = port; TcpChannel channel = new TcpChannel (props, null , provider); ChannelServices.RegisterChannel (channel, false ); RemotingConfiguration.RegisterWellKnownServiceType (typeof (ERP. Businesslogic.salescontractmanager), "Remotingservice" , WellKnownObjectMode.SingleCall) ;
Here is the code to write the dead service class, you can use the configuration file to increase the service class, but also by the reflection of the method to increase the service class.
The code for the client call is as follows:
Isalescontractmanager Salescontractmanager = (ipdmserver) activator.getobject (typeof( Isalescontractmanager),string. Format ("{0}remotingservice", Applicationserverurl)); if null) Throw New Appexception ("Sever configuration Error"); Salescontractmanager.savesalescontract (GUID, salescontract);
Improve server-side code, let the server actively search the system to hit the communicationservice features of the service class. When a new service type is added, the framework automatically recognizes and loads the service type:
Assembly Assembly =typeof(Manager). Assembly; Type[] Types = assembly. GetTypes ();foreach(Type typeinchTypes) {if(Type. Namespace = ="ERP. Businesslogic.managers ") {stringServiceName =string. Empty;Object[] attributes = type. GetCustomAttributes (typeof(Communicationservice),true);if(Attributes. Length > 0) serviceName = type. Name;if(!string. IsNullOrEmpty (ServiceName)) {if(Clientactivatedservices.contains (ServiceName)) {Remotingconfiguration.registeractivatedservicetype (type); }Else if(Singletonservices.contains (ServiceName)) {RemotingConfiguration.RegisterWellKnownServiceType (type, ServiceName +". rem", Wellknownobjectmode.singleton); }Else{RemotingConfiguration.RegisterWellKnownServiceType (type, ServiceName +". rem", WellKnownObjectMode.SingleCall); } }
This saves the developer's service release time. The main methods of the client are as follows:
Instance = reflectionhelper.createobjectinstance<t> (type);
. NET Remoting identifies whether the current service type is registered and, if there is one, creates a remote proxy that enables the request to be sent to the server.
To control the number of client concurrency:
. NET Remoting supports a single-piece invocation pattern, where the server side will only be the same object regardless of the number of calls, thus enabling session sessions to be controlled. ERP System users login, check the server login session table (session, essentially a DataTable), to determine whether it has been logged in. Concurrent user control can also be implemented, which prevents login when the number of users logged in exceeds the number of users authorized by the license.
The server crashes, the client is notified, suspends the current data entry operation, and the client can automatically reconnect when the server is available:
. NET Remoting supports client-server subscription patterns, and the server can send messages to clients. When the server process crashes, or cannot connect to the database, and so on, it is necessary to send a message notification to the subscribed clients in time, the client interface should immediately suspend the ERP main interface after receiving the notification, no action is allowed. This avoids the user hard input data, click Save but not connected to the server, had to turn off re-entry.
Security control, the application server blocks the connection of an unauthorized or unsigned application:
Server Control Client Connection call, when the client log in, need to pass in the current client assembly version, signature identity token, as well as system parameters, the server will be the parameters of the integration together, with MD5 to calculate a hash value. Only after the parameter value passed by the client passes the MD5 operation, the value after the MD5 operation of these same parameter values in the server is exactly the same. The server side allows the client to continue logging in.
When a server-side discovery error occurs, the support stack passes back to the client to diagnose the cause:
In the code above to create the server side, the following two sentences are intended for the server-side stack to be uploaded back to the client, refer to the following code:
New BinaryServerFormatterSinkProvider ();p Rovider. TypeFilterLevel = Typefilterlevel.full;
Supports data encryption and data compression:
Using a custom GTCP channel communication, this channel supports both encrypted and data compression transmissions.
Easy to develop and deploy:
The Code Smith 6.5 template will help generate Isalescontractmanager and Salescontractmanager two types of source code, as explained above, The deployment of the service class is implemented only by adding the Communicationservice attribute to Salescontractmanager.
The client delivers large file performance to the server:
To improve performance, for the file Transfer class service, open a separate port for file transfer.
Analysis of distributed Application pattern design and implementation of large. NET ERP System