I am developing a line of business application which has to, for reasons out of my control, use a client server architecture.
I.e. clients all connect to an application server, application server connects to database etc.
To do this in the past I have created a WCF service which exposes CRUD type methods for the database. Methods like this, exist in WCF:
Customer GetCustomer(int customerId);
List<Customer> GetAllCustomers();
etc...
However I have always found the same 2 problems with this:
1) There's a LOT of plumbing code which connects: client -> app server -> db server
2) When client applications need to grab more complex data, I end up having to add methods on the server side which end up something horrible like this:
Customer GetCustomerByNameWhereCustomerHasBoughtProduct(string name, int productCode);
OR
Or returning way more data than need and processing on the client side. Which is slow and really bad for the database. Something like:
List<Customer> customers = _Service.GetAllCustomers();
List<Product> products = _Service.GetAllProducts();
List<Customer> customersWhoBoughtX = (from c in customers where
c.OrderLog.Contains(products.Where(p => p.Code == x)
select c).ToList()
What am I doing wrong here because this must be solvable some way.
Is there a way to expose a database through a wcf service using conventions? Or any other idea that could help what I'm doing?
Ideally I would say the clients could connect to the database directly, however I am told this is an issue which can't be changed.
I would really appreciate some pointers.
Thanks