Search code examples
wcfdto

Should objects exposed via WCF services be DTO only?


I have a WCF application that have a bunch of domain entities (mapped by NHibernate) and service contracts. Currently I'm exposing entities directly via service contracts to WCF clients. But this causes me to encounter many limitations of WCF data contracts specially those related to serialization. For example circular graph limitation, KnownTypes etc.

It seems a better way is to use entities just in server side and using DTOs to transfer objects between WCF server and client. Am I right? Is it a must to be?


Solution

  • WCF is a message-based system - it connects clients and servers basically via XML serialized data messages. Therefore, WCF can only send back and forth static data - it's not a "remote procedure call" or "remote object" system where you'd have functionality transferred from cilent to server and back.

    Since anything WCF transfers must be XML serializable, it's really just about data - and so yes - WCF is best suited to just send back and forth DTO style data objects.