WCF / Client applications - where should the business logic go?

We are creating a WCF web service using WSSF. The idea is that it will provide our main database through the service and allows us to create various applications and websites on top of the service. At the moment, I am creating a simple client application that will download some data from this service, manipulate it, and then provide it to the user in the form of a CSV report file.

Now the question is, where should the business logic (which manages the data) be located? I decided that I would put him in the service. I already have a business layer with simple objects that map almost one to one with the database (customer, order, etc.). I decided that I would make several "higher level" objects to manipulate the data. For example, using a client, order and other objects, creating a report, etc. I thought the best place for this would be in the business layer for service. Thus, we could reuse this logic for various applications, if necessary.

Unfortunately, my boss does not agree. He wants to "sort out the problems" and said that the right place for this logic will be in the business layer inside the client application, and not in the service. I think it might be easier, but I would like to use my powerful object model inside the business service level to write this code. The objects exposed by the service are not “real” objects and in fact are only light data structures without the possibility of a complete object model that exists within the business level of the service.

What do you guys think? Thank you for help.

Cheers Mark

+7
c # design-patterns wcf wssf
source share
3 answers

My vote will be clear:

  • put so many data integrity checks in the database
  • puts any other business logic checks into the business logic level on the server side of the service.
  • put only simple checks at the client level, such as the "required field", etc., optimally automatically determined from the database model or your business model.

Why a database?
SQL in any form or form has some very simple and very powerful validation features - make sure the material is unique, make sure that the relational integrity between the tables is specified, etc. - USE IT ! If you perform these checks in a database, then no matter how your user ultimately connects to your data (horror scenario: managers can directly connect to your tables using Excel for working with business intelligence ...... ), these checks will be valid and will be respected. Ensuring data integrity is the maximum requirement in any system.

Why is the business logic on the server?
For the same reason, the other defendants mentioned: centralization. You do not want to have business logic and your checks only in the client. What should I do if any other department in your company or a third-party external consultant suddenly starts using your service, but all the checks and checks of the business are missing, because they do not know about them? Not good......

Customer logic
Yes, of course, you also want to put some simple checks in the client, especially if it is a web application. Things like “this field is required” or “maximum length for this field”, etc., should be done as early as possible. Ideally, this will be automatically picked up by clients from the database / service level. ASP.NET server controls have a client check that can be automatically turned on, Silverlight RIA services can get the data restriction in your underlying data model and pass it to the client level.

+7
source share

I think the “right” depends on the architecture of your application. Of course, there is a certain difference in the separation of problems. It looks like your boss feels that the current model should use the server as a data access layer that maps the database to business objects and that the business logic should be implemented on the client.

You may still have a split question about whether business logic is implemented on the client or server. This is not the place where you do the processing, which takes into account, but how clearly you have developed the interfaces between the layers of the application.

This can help to learn more about the client. Are you dealing with a browser / Javascript client? If so, I would save as much processing as possible on the server and send the data to the client more or less in the form that you want to display.

If this is a C # client, then you have more options to work for this purpose. You could probably restore WCF service responses to the same business object classes that you used on the server side and get the same power as on the server. (Just separate the business object classes between the two solutions.)

0
source share

There is no hard and fast rule for this, but in this case I would say that your boss is no longer right than you.) Everyone will have a slightly different opinion on this subject, and there may be several reasons why your business logic is placed in places other than the business level, but you can rarely put it in a client application - you can argue that when it is in the client application, it is a user interface or presentation rule, not a business rule.

If web services will be used by a number of applications, then, as far as possible, you need the business logic on the web service side. I really would have a very subtle webservice level, all it does is take the call and then transfer the execution to the real business layer. I would also have a mapping between the database data and the business data objects executed at the database level, and not with the business level.

0
source share

All Articles