问题描述
我正在开发大学管理系统,我在该系统上使用 WCF 服务,并且在该服务中我使用 DataTables 和 DataSets 从数据库中获取数据,而数据库是 sql server.
I am working on University Management System on which I am using a WCF service and in the service I am using DataTables and DataSets for getting data from database and database is sql server.
我的问题是
- 使用数据表和数据集是好做法"还是坏做法"?
- 如果不好,DataTable/DataSet 的替代方案是什么?
- 如果不好,主要原因是什么?
推荐答案
从 Web 服务返回数据集通常不被视为良好做法".这些问题已在以下链接中详细记录:
Returning data sets from web services is not typically considered a "good practice". The issues have been documented thoroughly in the following links:
http://msdn.microsoft.com/en-us/magazine/cc163751.aspx一个>
http://www.4guysfromrolla.com/articles/051805-1.aspx
http://msdn.microsoft.com/en-us/magazine/cc188755.aspx
总之,从 Web 服务返回 DataSet
对象的最大问题似乎涉及序列化性能、非 .net 互操作性.此外,DataSet
的通用、多态性质通常在运行时之前的数据结构较高,因此,WSDL 定义没有提供方法签名的完整描述.然而,与任何设计决策一样,您需要权衡成本与收益,并根据您的特定目标和限制确定最合适的方案.
In summary, the biggest issues with returning DataSet
objects from web services seem to involve serialization performance, non-.net interoperability. In addition, the generic, polymorphic nature of the DataSet
generally high the data structure until runtime, as such, the WSDL definition does not provide a complete description of the method signature. As with any design decision, however, you need to weigh the costs vs the benefits and determine the best fit given your specific goals and constraints.
就替代方案而言,您可以考虑使用通用集合(例如 List<yourClassHere>
),或者甚至考虑进行一些架构修订以允许使用 ODATA.
In terms of alternatives, you could consider using a generic collection (e.g. List<yourClassHere>
) or maybe even consider some architecture revisions to permit the use of ODATA.
以下链接为通过 Web 服务返回实体提供了一些很好的背景参考.http://msdn.microsoft.com/en-us/library/orm-9780596520281-01-14.aspxhttp://www.codeproject.com/Articles/127395/Implementing-a-WCF-Service-with-Entity-Frameworkhttp://msdn.microsoft.com/en-us/data/hh237663.aspx
The following links provide some good background reference for returning entities via web services. http://msdn.microsoft.com/en-us/library/orm-9780596520281-01-14.aspx http://www.codeproject.com/Articles/127395/Implementing-a-WCF-Service-with-Entity-Framework http://msdn.microsoft.com/en-us/data/hh237663.aspx
这篇关于为什么从 WCF 服务返回数据集或数据表不是一个好习惯?什么是替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!