简体   繁体   English

从WCF中检索数据表而不使用数据传输对象的最佳方法是什么

[英]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.

相关问题 将数据从SqlDataReader传输到List的最佳方法是什么 <SomeClass> ? - What is the best way to transfer data from SqlDataReader into List<SomeClass>? 在不使用数据库的情况下,为桌面存储/检索数据的最佳方法是什么? - What's the best way to store/retrieve data for a desktop without using a database? 从 2 个表中检索数据以填充在 C# 中包含另一个对象列表的对象列表的最佳方法是什么? - What's the best way to retrieve data from 2 tables for filling a list of objects that has another list of objects inside it in C#? 使用WCF服务数据结构的最佳方法是什么 - What is the best way of using WCF Service data structures 使用odp.net和pl / sql存储过程从oracle表检索数据的最佳方法是什么? - What is the best way to retrieve data from an oracle table using odp.net and pl/sql stored procedures? 从数据表中删除重复项的最佳方法是什么? - What is the best way to remove duplicates from a datatable? 从数据表中获取记录的最佳方法是什么? - What is the best way to get records from Datatable? 将数据从视图传输到javascript的最佳方式 - Best way to transfer data from view to javascript 从ClaimsIdentity检索WindowsIdentity的最佳方法是什么 - What is the best way to retrieve a WindowsIdentity from a ClaimsIdentity 从数据表中检索数据 - Retrieve Data From DataTable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM