Data Contracts & Business Entities

Topics: General Discussion Forum, July and December Releases Forum, Service Factory Modeling Edition Forum
Mar 17, 2008 at 9:56 PM
While building services using the WCF WSSF, I've ran into the situation multiple times where I have simple business entites (with no logic) as well as data contracts which have identical implementations (other than the DataContract attributes). This is also true for Enums that I've defined. They exist both in the BusinessEntities project as well as the DataContracts project. I was wondering if it is a good idea for these situations to eliminate the DataContract classes so we do not have duplicate implementations and flag the BusinessEntities with the DataContract attributes. These duplicate classes generate a large maintenance overhead, since we need one class in the Business Entities project, one class in the Data Contracts project, and then a translator that does a straight forward mapping between the two. What is the best practice to handle these types of situations? I need to present a good explanation of why we need both of these to my development team.
Developer
Mar 18, 2008 at 10:24 AM
The basic idea around Data Contracts is related to the concept of a "reusable type" and is part of the agreement between the client and the service regarding data transfer. In this regard, there's no need to share the BEs so they can be completly abstracted and encapsulated inside your organization. So the best practice dictates that you may have DCs and BEs regardless of its structurres and internal usage because DCs are only designed to be part of the client-service contract.
Regarding the 1-1 mapping between DCs and BEs, this is not required and you can have in your designs, DCs that may encapsulate/consolodate more BEs or collections of BEs and therefore you'll have more freedom to build your contracts according to each service operation.
On the other hand, the translators add another level of indirection but you will have more control of what is exposed to the outside world and what's inside your organization that may not be exposed or is not required for communication purposes.
Mar 18, 2008 at 3:06 PM
What if both ends, the service & the client, are controlled within our organization and nothing is exposed to the outside world. Would the same ideas still hold true?
Mar 18, 2008 at 3:09 PM
What if both ends, the service & the client, are controlled within our organization and nothing is exposed to the outside world. Would the same ideas still hold true?
Developer
Mar 19, 2008 at 8:04 AM
Yes, same idea since the point of the "public" concept is actually from a boundary standpoint and not to the way your company integrates with the outside world.