I need to path information from BL layer to the presentation layer via WCF services .
I thought to do it via DataSets but I saw that people tell that it’s a bad practice and it’s recommended to use dataclasses.
Can someone explain the difference and the advantages .
Thanks for help.
DataSet is an old-school, outdated like-an-OR/M solution which worked fine for a long time in drag&drop developments.
Once you want to expose some logic over a service using WCF or any other framework, you need to take in account that these should transport no useless data and just what client needs to consume, and a client could be an user interface or just another service or backend engine.
In services like WCF the best approach is DTO (data-transfer objects, also known as value objects), which are a light-weight versions of business objects, absolutely unlinked from any layer (it doesn’t depend on business, UI, data…) which can be easly serialized into XML or JSON and deserialized in any platform, not only in strongly-typed environments, but also interpreted, dinamically-typed ones, like JavaScript, PHP, Python or Ruby (or many others).
Think about DTO as a class which has the exact number of properties that some consumer needs to work with your service layer.
Practical example: You’ve a Person class having a Name, SecondName and Age. In your user interface, you need to query some service for a list of Person and there you need to show SecondName only. In this case, you’re going to design a class having a single property SecondName and you’ll avoid giving a full Person to the user interface through your service layer, because it’s cheaper and, obviously, optimal.
If this service layer returns PersonDto objects, a JSON-serialized list of 3 persons would be
[{ "SecondName": "Blah" }, { "SecondName": "Bleh" }, { "SecondName": "Blih" }]. I don’t think a DataSet would be that lighty serialization.Check these articles about DTO: