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.

2 Answers 2


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().


Just abstract the web service into a domain service and encapsulate it inside an implementation. That is why services in DDD exist. To abstract and encapsulate the outside world.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.