Daniel Auger:
As others have said, this is possible. However, if both the service and the client use an object that has exactly the same domain behavior on both sides, you probably did not need the service in the first place.
Lomax: I have to disagree with this, as this is a somewhat narrow comment. Using a webservice that can serialize domain objects into XML means that it makes it easy for clients who work with the same domain objects, but it also means that these clients are limited using this particular web service you opened, and it also works in on the contrary, letting other clients not own their domain of objects, but still services through XML.
@Lomax: You described two scenarios. Scenario 1: The client translates the XML message back to the same domain object. I believe this is an "object return". In my experience, this is a bad choice, and I will explain it below. Scenario 2: The client rehydrates the xml message to something other than the same domain object: I am 100% behind this, however I do not believe that this returns a domain object. It does send a message or DTO.
Now let me explain why true / clean / non-serializing DTO objects via a web service is usually a bad idea. Statement: in order to do this, first of all, you must either be the owner of both the client and the service, or provide the client with a library to use so that they can re-fit the object back to its true type. Problem. This domain object as a type now exists and belongs to two semi-connected domains. Over time, behavior may need to be added to one domain that does not make sense in another domain, and this leads to pollution and potentially painful problems.
I usually use scenario 2. I use only scenario 1, when there is every reason for this.
I apologize for being so brief with my initial answer. Hope this clears me to some extent as I understand it. Lomax, it would seem, we agree;).
Daniel Auger
source share