[英]what is the best way to retrieve a datatable from WCF without using Data transfer objects
I am new to WCF and from what I have researched I understand it's not a good thing to return a dataset or a datatable from a WCF service. 我是WCF的新手,根据我的研究,我了解从WCF服务返回数据集或数据表不是一件好事。 I also understand that the best way is convert your data into a DTO and then pass it on to the client.
我也了解,最好的方法是将数据转换为DTO,然后将其传递给客户端。
The problem I am facing is that I need to create some reports that can have different number of columns and I only want to create one method in my web service to retrieve the data based on query name that will be supplied as a parameter. 我面临的问题是,我需要创建一些可以具有不同列数的报表,而我只想在Web服务中创建一个方法来根据将作为参数提供的查询名称来检索数据。 This makes it difficult for me to create a object class and map it to my data table as the number/type of columns would be different for each report.
这使我很难创建对象类并将其映射到我的数据表,因为每个报表的列数/类型将有所不同。
What is the best way to achieve this? 实现此目标的最佳方法是什么? I have gone through a number of blogs but still haven't found a good way of doing this.
我浏览了许多博客,但仍然没有找到一种很好的方法。
EDIT : I tried returning a datatable and got some errors which lead me to the blogs that explained why datasets/datatables were not a good idea for returning data in webservices. 编辑:我尝试返回一个数据表,但遇到一些错误,这些错误使我进入了博客,这些博客解释了为什么数据集/数据表不是Web服务中返回数据的好主意。
Not sure about " the best way ", but you can try to return xml file/xml string instead of DataTable
from WCF. 不确定“ 最佳方法 ”,但是您可以尝试从WCF返回xml文件/ xml字符串而不是
DataTable
。 Convert your DataTable
to xml using DataTable.WriteXml , then later service consumer can convert the xml back to DataTable
using DataTable.ReadXml . 将您的
DataTable
使用XML DataTable.WriteXml ,后来服务消费者可以将XML转换回DataTable
使用DataTable.ReadXml 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.