Alternatives for Translation Layer in SOA: WCF
Asked Answered
E

2

3

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
Eleanoraeleanore answered 28/2, 2012 at 11:15 Comment(2)
Alternative to what? What problem are you trying to solve here?Mosaic
@Oded. Alterantive to "Translation Layer" approachEleanoraeleanore
C
4

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.

Coulometer answered 29/2, 2012 at 9:24 Comment(2)
Thank you. I have a question posted based on your last comment - "If you are building a completely new system, perhaps it'll be easier not to translate.". Could you please answer #9499462 ?Eleanoraeleanore
@Lijo: I think Mark means that if the entire purpose of your system is to expose certain information via WCF, you may architect your system so that your data-layer Entities directly model the values you expect to pass to and from your service. If your system has a variety of other responsibilities, you probably only want to expose a small subset of that data via the WCF service.Shears
D
1

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

Doge answered 28/2, 2012 at 11:20 Comment(4)
Thanks. Though it will automate the process, it will have code for this dedicated task - the translation. Is it a good practice to have the translation or totally forget OOAD?Eleanoraeleanore
Personally i like to keep translation "under control". The "Entities" we expose in our services will have been transformed by automapper from the source data types the service consumes, ie, other entities. It gives us fine grained control on ouput transformation, while maintaining compile time type checking.Doge
Does AutoMapper produce "Operation specific DTO" or "DTO from domain without behavior"?Eleanoraeleanore
AutoMapper only maps. It doesn't create the DTO classes - you do. This means you decide whether the DTO contains all, most of, or just some of the fields from the original entity.Screeching

© 2022 - 2024 — McMap. All rights reserved.