views:

304

answers:

3

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!

+2  A: 

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.

codemeit
A: 

I think there should be only one data access layer in your application. So, if you create a service and get the data from that, by all means remove every direct data connection from your client.

This also means that you don't have to make your database public, and also, the chance of anyone tampering with your database will be quite low.

Venemo
+1  A: 

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).

Joachim Kerschbaumer
This is exactly my situation as I am also using nhibernate and I do have repository interfaces and then the repository implementations on a separate library. Are there any concrete examples out there that does this via a service that I could look at?
kaivalya
i´m sorry i can´t give you access to our code base. however, if you just access an interface from within your client app, you don´t have to care about the actual implementation. when it comes to transmit nhibernate entities via wcf, take care of serialization issues with lazy-loaded collections. wcf does not like nhibernate proxies
Joachim Kerschbaumer