Publish data access to the WCF Service (source code)

Source: Internet
Author: User

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.

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.