DDD and Web Services – Domain Object Calling a Web Service

designdomain-driven-designsoaweb services

Is it ok to call a webservice from a Domain object?.

As I write the question I am thinking that you should never do that, as it is poor design, but the situation is the following:

I have a domain object called Postman that works very closely with a Message object. This Message is provided by a web service. Without the Message, the Postman object could not do its business logic.

I understand that this code doesn't smell good but, since the Postman depends on the Message, it seems logical to call the web service in order to get the Message.

There is no other way to get the Message without the web service.

Best Answer

What would you do if the message was in a database? Do the exact same thing. A web service is just another storage device, in essence.

Your calling code should know nothing of the repository implementation details, if at all possible. Database, text file, web service, it's all GetMessage().