Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving Data access layer to WCF service

I am at a stage of building a wcf service for my application that will provide the products.. I have, the domain model and persistence layer under the application.

For the service I will also need a similar domain model and persistence layer. I don't want to duplicate things and I don't want to also share libraries and couple the application and service either.

So this make me think if I should create either a separate service(or implement in this new one I'm creating) the data access layer and use that service for the data access from the appication also, hence there will be only one data access layer that is shared by both the application and the service

Is this a good pattern and are there major problems that await for me down the road, if so what would be your suggestion? Thanks!

like image 743
kaivalya Avatar asked Nov 14 '22 14:11

kaivalya


2 Answers

i once was in the same situation you are. at first during development, there were no wcf services for data access available, so i used nhibernate for data access. to ease switching from direct nhibernate access to wcf services for data retrieval, i had something like :

client app -> Repository Interfaces -> Repository Implementations (at first this one retrieved the data through nhibernate, the second implementation via wcf).

having an interface that hides the implementation details from your application code may be a suitable solution for your problem. (btw, the nhibernate data access code was mainly reused on the server side, so you won´t have to throw stuff away).

like image 58
Joachim Kerschbaumer Avatar answered Dec 22 '22 09:12

Joachim Kerschbaumer


If you had WCF services as resource access layer, you could just move your existing data access layer away from your client application because your WCF web service is the endpoint for data exchange.

At the moment,

Client App <-> Database Access

This is bad practice, it exposes your database public and the port of database might have been blocked by default.

with web service,

Client App <-> Web Services(Database access)

It should have appropriate security implementation(HTTPS and Authentication). Web service is normally hosted on friendly port 80 and you don't have to expose the underlying database public at all.

like image 39
Ray Lu Avatar answered Dec 22 '22 11:12

Ray Lu