WCF - way of using data contracts
If I have a core class which is used internally by all the modules and then I would like to publish a wcf service which would make use of this class... then what is the best way to do that? Is it better to mark it as data contract directly, o开发者_开发问答r better create a new class as data contract which either inherits or maps to the core structure or ... what do you suggest guys?
Either will work, since in most cases the client will be getting a WSDL/MEX representation - not your type directly. In either case, remember to use explicit [DataContract]
/[DataMember]
attributes so that it truly is contract-based, rather than looking at the fields.
(note: don't inherit a DTO from your domain type; a DTO should be separate, if you go that route)
Personally, I prefer a separate DTO, but I know people have success exposing the domain model directly (that is how LINQ-to-Data-Services works, for example).
精彩评论