Which layer should I have my DataContracts?
Should I have them in the wcf client app?
Or should I put them in the business or data layer?
On the one hand, serialize and de-serializing of data, I may require interaction with other data objects so it would fit that I should put that business logic in the business or data layer.
On the other, these datacontracts and associated business rule开发者_C百科s are not and should not be used by say, my web app and is related purely to the wcf web service itself.
From a pure SOA persective, they should have their own layer dedicated to modeling the interface you want to expose to the outside world.
More to the point, if the business logic is important you could move the datacontracts (DC) in a separate assembly and share it between clients and services. It brings you several benefits:
- No need to create a proxy class on the clients for the DC
- You can share the DC internal logic easily
If you want to add additional logic on the server side that should not be known to client, you can still extend the classes through composition or sub-classing (or even extension methods).
精彩评论