<p>Typical scenario. We use old-school XML Web Services <em><code>internally</code></em> for communicating between a server farm and several distributed <em>and</em> local clients. No third parties involved, only our applications used by ourselves and our customers.</p>

<p>We're currently pondering moving from <code>XML</code> <code>WS</code> to a <code>WCF/object-based</code> model and have been experimenting with various approaches. One of them involves transferring the domain objects/aggregates directly over the wire, possibly invoking DataContract attributes on them.</p>

<p>By using <code>IExtensibleDataObject</code> and a <code>DataContract</code> using the Order property on the <code>DataMembers</code>, we should be able to cope with simple property versioning issues (remember, we control all clients and can easily force-update them).</p>

<p>I keep hearing that we should use dedicated, transfer-only Data Transfer Objects (<code>DTOs</code>) over the wire.</p>

<p>Why? Is there still a reason to do so? We use the same domain model on the server side and client side, of course, prefilling collections, etc. only when deemed right and "necessary." Collection properties utilize the service locator principle and IoC to invoke either an <code>NHibernate-based</code> "service" to fetch data directly (on the server side), and a <code>WCF</code> "service" client on the client side to talk to the <code>WCF</code> server farm.</p>

<p>So - why do we need to use <code>DTOs</code>?</p>

[{'answer_id': 28710, 'author': 'akmad', 'author_id': 1314, 'author_profile': 'https://Stackoverflow.com/users/1314', 'pm_score': 4, 'selected': True, 'text': '<p>In my experience DTOs are most useful for:</p>\n\n<ol>\n<li>Strictly defining what will be sent over the wire and having a type specifically devoted to that definition.</li>\n<li>Isolating the rest of your application, client and server, from future changes.</li>\n<li>Interoperability with non-.Net systems.  DTOs certainly aren\'t a requirement, but they make it easier to design "safe" types.</li>\n</ol>\n\n<p>In your scenario these design features may not matter that much.  I\'ve used WCF with both strict DTOs and shared Domain Objects and in both scenarios it worked great.  The only thing I noticed when sending Domain Objects over the wire was that I tended to send more data (and in unexpected ways) then I needed to.  This was likely more due to my lack of experience with WCF than anything else; but it\'s something you should definitely be wary of should you choose to go that route. </p>\n'}, {'answer_id': 38560, 'author': 'Ubiguchi', 'author_id': 2562, 'author_profile': 'https://Stackoverflow.com/users/2562', 'pm_score': 3, 'selected': False, 'text': "<p>Having worked with both approaches (shared domain objects and DTOs) I'd say the big problem with shared domain objects is when you don't control all clients, but from my past experiences I'd usually use DTOs unless it development speed were of the essence.</p>\n\n<p>If there's any chance that you won't always be in control of the clients then I'd definately recommend DTOs, because as soon as you share your domain objects with someone else's client application you start tying your internals to someone else's dev cycle.</p>\n\n<p>I've also found DTOs useful when working in a versioned service environment, which allowed us to radically change the internals of our app but still accept calls to the old versions of our service interfaces. </p>\n\n<p>Finally, if you have a lot of client applications it might also be beneficial to use DTOs as you're then protected with an easily versionable service.</p>\n"}]
['https://Stackoverflow.com/questions/25323', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2741/']