Recently, a project was designed to maximize its implementation reuse.SOA. Detach a service from a hierarchy as an Application Service (AsAnd device services (DS), And useWCFService. In this way, you only need to modify the actual hardware configuration in future projects.DS.
There are indeed many advantages to adopt this architecture, but there are higher service requirements when implementing it: loose coupling, more stable, and well-developed compensation policies for exceptions. ProjectUIMust startClientLoginAsIn this way, whenAsDetectedClientAfter logging on, the latest business data and status data are stored inAsWhen "Think It is necessary", "push"ClientDisplay. In addition, when you need to access the databaseUINeed to callAsReleased data access interface.
Publish data accessWCFThe service is similar to the followingDemo:
1,Service Contract (Service contact)
Service contactStatement inIdataaccessor. CSFile. The statement is as follows:
Service Contract: data access interface
[Servicecontract]
[Serviceknowntype ( " Getknowntypes " , Typeof (Knowntypesprovider)]
Public Interface Idataaccessor
{
[Operationcontract]
Bool Selectsinglerecord ( String Tablename, String Whereclause, Out _ Record );
[Operationcontract]
BoolSelectrecordlist (StringTablename,StringWhereclause,OutArraylist recordlist );
[Operationcontract]
BoolModifysinglerecord (_ record );
[Operationcontract]
BoolModifyrecordlist (arraylist recordlist,BoolBintransaction );
}
Service contactBoth the server and client must be referenced.
2,Data Contract (Data contact)
Data contactStatement inTestwcf. CSFile.ToolsGenerate.Data contactBoth the server and client must be referenced.
3,Service implementation
Dataaccessor. CSFile to implement4Interfaces. This mainly appliesOledbdataaccessor.
4,Service bearer
InApp. config"<System. servicemodel>"Mark to addWCFServer configuration, including service name, address, binding method, and implementationService contact. TheNettcpbinding. In addition, the object implementing the service needs to be instantiated and stored inServicehostCan be accessed by the client.Program. CS.
5,Client implementation
Client Access through proxy classWCFThe compilation of services and proxies is more mechanical.Dataaccessorproxy. CSAndApp. config"<System. servicemodel>"Mark to addWCFThe client configuration tells the proxy class where to access the service. After that, you can call the service published by the server through a proxy in the interface logic.
DemoMediumWCFServicePrevious demoAgain, becauseClientAndServerEnd is actually causedTCPTo avoidTCPDisconnection exception,ClientThe client implements automatic reconnection.
Complete source code project can be clickedHereDownload.