Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 3 down vote accepted

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

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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