Pavol
Pavol

Reputation: 572

Should I use self hosted WCF as client or direct connection to database?

I have a question about WCF and database connection... I have console application as server with some logic in it. Then I have WPF application that can run on multiple computers that connect to server and get some data from it. I also need to work with database.. so I decided to create WCF service that connect to database with Entity Framework . So far, so good.. now all clients have acces to WCF service.. But I aslo want to connect to database with my server that host this WCF service.. I found some tutorials how to create connection from app that host service as client. But I am not sure if its good idea.. So I want to ask.. it's better to use WCF service from host application as client.. or should I just use dbContext from this application. Will not there be a conflict between service and direct using dbContext ? When multiple clients will connect thrue service and server will connect thrue context?

Upvotes: 0

Views: 180

Answers (1)

Houssam Hamdan
Houssam Hamdan

Reputation: 908

I will provide some pros and cons for choosing to put WCF in the middle.

Pros

1- Enhanced Security. Grant db access only to server hosting the WCF service. The machines where app is installed need not to know the database ip address. Also, you can setup security on the message level with WCF.

2- Provide reusable API to multiple UIs.

3- You can implement your business logic in a centralized and consistent API so changes to business logic will not affect the client apps.

Cons

1- Performance Cost. You always have to consider this fact that putting additional network requests affect the performance of your app.

2- More code and more hardware to maintain.

Remember, complexity must be justified. Adding a WCF in the middle is adding complexity to your system. If not justified, then you dont need it.

Upvotes: 1

Related Questions