3
votes

Services are not object-oriented. Suppose I have a OOAD based design. We can convert it into DTO (that does not have any behavior) using a Translation Layer. But this can cause be very big increase in amount of code. What are the alternative ideas for this in WCF (via C#)?

Please have your comment whether it is good idea to have such a transition between SOA and OOAD. Should we avoid OOAD altogether when we have SOA or use such mapping techniques?

Is it a good idea to create "Operation Specific DTO" rather than creating "DTO directly from domain after removing behavior" ? Is there any tool for the "Operation Specific DTO Approach"?

Does AutoMapper produce "Operation specific DTO" or "DTO from domain without behavior"?

Note: Operation specific DTO approach can be referred in the answer in “Do not use Abstract Base class in Design; but in Modeling/Analysis”

Extract from Service Layer Guidelines

Design transformation objects that translate between business entities and data contracts.

REFERENCES:

  1. How to restrict web service data contract properties based on user role
  2. SOA Question: Exposing Entities
  3. What is the best way of using DTOs in a SOA application?
  4. WCF Message & Data Contract, DTO, domain model, and shared assemblies
2
Alternative to what? What problem are you trying to solve here?Oded
@Oded. Alterantive to "Translation Layer" approachLCJ

2 Answers

4
votes

As with everything else in software development (and particularly architecture), there's not a single, correct answer to those questions. It depends upon the architectural goals and constraints.

WCF works with DTOs. While it's possible to drop down to a more primitive layer and work directly with messages, for all practical concerns, DTOs are a fundamental part of working with WCF. Since WCF seems to be one of the architectural constraints in this case, there's really no practical way to avoid DTOs.

The question then becomes: should there be a mapping layer or not?

That question is fairly easy to answer if we can answer another question: mapping from what?

If you already have an existing system, you'd need to translate between the existing system and the WCF boundary. In such a case, a translation layer is required.

If you are building a completely new system, perhaps it'll be easier not to translate.

1
votes

Check out Automapper, we are using this for the same task.