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.
我正在使用大学管理系统,我正在使用WCF服务,在服务中我使用DataTables和DataSets从数据库和数据库获取数据是sql server。
My questions are
我的问题是
- Is using DataTables and Datasets "Good Practice" or "Bad Practice" ?
- If it is bad, what is the alternative of DataTable/DataSet ?
- If it is bad, what are the main reasons ?
使用DataTables和数据集“良好实践”还是“不良实践”?
如果不好,DataTable / DataSet的替代方案是什么?
如果不好,主要原因是什么?
3 个解决方案
#1
10
Returning data sets from web services is not typically considered a “good practice”. The issues have been documented thoroughly in the following links:
从Web服务返回数据集通常不被视为“良好实践”。这些问题已在以下链接中详细记录:
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
http://msdn.microsoft.com/en-us/magazine/cc163751.aspx http://www.4guysfromrolla.com/articles/051805-1.aspx http://msdn.microsoft.com/en-us/杂志/ cc188755.aspx
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.
总之,从Web服务返回DataSet对象的最大问题似乎涉及序列化性能,非.NET互操作性。此外,DataSet的通用多态性通常会使数据结构高到运行时,因此,WSDL定义不提供方法签名的完整描述。然而,与任何设计决策一样,您需要权衡成本与收益,并根据您的具体目标和约束确定最佳匹配。
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.
在备选方案方面,您可以考虑使用通用集合(例如List
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
以下链接为通过Web服务返回实体提供了一些很好的背景参考。 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
#2
1
There are 3 reason for failed return type as datatable
in WCF services
在WCF服务中,返回类型失败的原因有三个作为数据表
-
You have to specify data table name like:
您必须指定数据表名称,如:
MyTable=new DataTable("tableName");
-
When you are adding reference on client side of WCF service select reusable dll
system.data
当您在WCF服务的客户端添加引用时,请选择可重用的dll system.data
-
Specify attribute on
datatable
member variable like在datatable成员变量上指定属性,如
[DataMember] public DataTable MyTable{ get; set; }
#3
-1
I am using DataTable
in my WCF application, but was getting an error. This is how I fixed the error.
我在我的WCF应用程序中使用DataTable,但是收到错误。这是我修复错误的方法。
When returning a DataTable from a web service in WCF to windows form application. I was getting this exception.
将DataTable从WCF中的Web服务返回到Windows窗体应用程序时。我得到了这个例外。
System.ServiceModel.CommunicationException: 'An error occurred while receiving the HTTP response to http://localhost:52968/MunerahService1.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.'
System.ServiceModel.CommunicationException:'接收到http:// localhost:52968 / MunerahService1.svc的HTTP响应时发生错误。这可能是由于服务端点绑定不使用HTTP协议。这也可能是由于服务器中止HTTP请求上下文(可能是由于服务关闭)。有关详细信息,请参阅服务器日志。
It happened any time I tried to retrieve a DataTable
它发生在我试图检索DataTable的任何时候
To fix the exception I needed to give the DataTable
a name.
要修复异常,我需要为DataTable命名。
code with the error
代码有错误
tab = new DataTable();
Fixed code to remove the excption
修复了删除摘要的代码
tab = new DataTable("Doctor_info");
#1
10
Returning data sets from web services is not typically considered a “good practice”. The issues have been documented thoroughly in the following links:
从Web服务返回数据集通常不被视为“良好实践”。这些问题已在以下链接中详细记录:
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
http://msdn.microsoft.com/en-us/magazine/cc163751.aspx http://www.4guysfromrolla.com/articles/051805-1.aspx http://msdn.microsoft.com/en-us/杂志/ cc188755.aspx
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.
总之,从Web服务返回DataSet对象的最大问题似乎涉及序列化性能,非.NET互操作性。此外,DataSet的通用多态性通常会使数据结构高到运行时,因此,WSDL定义不提供方法签名的完整描述。然而,与任何设计决策一样,您需要权衡成本与收益,并根据您的具体目标和约束确定最佳匹配。
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.
在备选方案方面,您可以考虑使用通用集合(例如List
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
以下链接为通过Web服务返回实体提供了一些很好的背景参考。 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
#2
1
There are 3 reason for failed return type as datatable
in WCF services
在WCF服务中,返回类型失败的原因有三个作为数据表
-
You have to specify data table name like:
您必须指定数据表名称,如:
MyTable=new DataTable("tableName");
-
When you are adding reference on client side of WCF service select reusable dll
system.data
当您在WCF服务的客户端添加引用时,请选择可重用的dll system.data
-
Specify attribute on
datatable
member variable like在datatable成员变量上指定属性,如
[DataMember] public DataTable MyTable{ get; set; }
#3
-1
I am using DataTable
in my WCF application, but was getting an error. This is how I fixed the error.
我在我的WCF应用程序中使用DataTable,但是收到错误。这是我修复错误的方法。
When returning a DataTable from a web service in WCF to windows form application. I was getting this exception.
将DataTable从WCF中的Web服务返回到Windows窗体应用程序时。我得到了这个例外。
System.ServiceModel.CommunicationException: 'An error occurred while receiving the HTTP response to http://localhost:52968/MunerahService1.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.'
System.ServiceModel.CommunicationException:'接收到http:// localhost:52968 / MunerahService1.svc的HTTP响应时发生错误。这可能是由于服务端点绑定不使用HTTP协议。这也可能是由于服务器中止HTTP请求上下文(可能是由于服务关闭)。有关详细信息,请参阅服务器日志。
It happened any time I tried to retrieve a DataTable
它发生在我试图检索DataTable的任何时候
To fix the exception I needed to give the DataTable
a name.
要修复异常,我需要为DataTable命名。
code with the error
代码有错误
tab = new DataTable();
Fixed code to remove the excption
修复了删除摘要的代码
tab = new DataTable("Doctor_info");