数据集VS数据类从WCF服务的返回类型 [英] DataSets vs DataClasses as return type from WCF services

查看:168
本文介绍了数据集VS数据类从WCF服务的返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从BL层通过WCF服务路径信​​息到presentation层。

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 .

感谢您的帮助。

推荐答案

DataSet是一个老派,过时样的-OR / M这工作得很好很长一段时间的解决方案的拖放放大器;下降的发展

DataSet is an old-school, outdated like-an-OR/M solution which worked fine for a long time in drag&drop developments.

在你想要使用WCF或其他任何框架,揭露了一些逻辑,在一个服务,你需要采取在考虑,这些在运输没有无用的数据,只是什么客户需要消耗,和客户端可能是一个的用户界面的,还是一种服务或后台引擎。

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.

在服务,如WCF最好的办法是的 DTO 的(数据传输对象的,也被称为的的值对象的),这是一个光业务对象,从任何一层完全无关联的-weight版本(它不依赖于业务,用户界面​​,数据......),它可以伊斯利序列化为XML或JSON和反序列化在任何平台上,不仅在强类型的环境,而且还跨preTED,dinamically类型的那些,如JavaScript,PHP,Python或Ruby(或其他许多人)。

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

想想DTO作为具有特性的确切人数,有些消费者需要与你的服务层工作的一类。

Think about DTO as a class which has the exact number of properties that some consumer needs to work with your service layer.

实例:的你一个的个人的类有一个名称,SecondName和年龄。在用户界面中,你需要查询一些服务的的个人的名单有你需要显示的 SecondName 的唯一。在这种情况下,你要设计有一个属性类的 SecondName 的,你会避免通过服务层的用户界面给人一种完整的个人的,因为它更便宜,很明显,最优的。

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.

如果该服务层返回的 PersonDto 的对象,3人的JSON序列化的列表将 [{SecondName:嗒嗒},{SecondName: 的Bleh},{SecondName:Blih}] 。我不认为一个的数据集的将是莱蒂系列化。

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.

查看这些文章的 DTO 的:

  • http://en.wikipedia.org/wiki/Data_transfer_object
  • http://msdn.microsoft.com/en-us/library/ff649585.aspx

这篇关于数据集VS数据类从WCF服务的返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆