简体   繁体   English

从WCF服务返回SqlDataReader

[英]Returning SqlDataReader from a WCF Service

My method currently executes a stored procedure, the results of which I can access through the SqlDataReader. 我的方法当前执行一个存储过程,可以通过SqlDataReader访问其结果。 Is it now possible for me to convert this to XML? 现在可以将其转换为XML吗? This is a wcf web service. 这是一个wcf Web服务。

As said above, if you're requesting data out of a WCF service, it will serialize to XML for you, send over the wire & your WCF client will deserialize - it's all done for you, no interaction required. 如上所述,如果您要从WCF服务中请求数据,它将为您序列化为XML,通过有线发送,并且WCF客户端将进行反序列化-一切都为您完成,不需要任何交互。

If you just want to go from data to XML, you can load your SQL reader to a DataSet, then get the XML from that dataset ( DataSet.GetXml() ) - while probably not the best/fastest way, it's quick and dirty. 如果只想从数据转换为XML,则可以将SQL阅读器加载到DataSet,然后从该数据集( DataSet.GetXml() )获取XML-虽然可能不是最好/最快的方法,但它又快又脏。 For a single table of data, the .net DataTable also has a WriteXml method that writes to file, stream, etc. 对于单个数据表,.net DataTable还具有WriteXml方法,该方法可写入文件,流等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM