编辑:为清楚起见更新了问题:我需要在内存中将 SSRS 字节流反序列化为数据集。
我需要从 VB.Net 获取 SSRS 报告并将结果放入数据集中。我可以读取和写入 XML 文件,但由于某种原因,我的大脑无法将 XML 报告直接放入数据集,以便我可以对其进行操作。
我可以获得报告并将其流式传输到 XML 文件:
Public Sub GetReportNames(serverName As String)
Dim rs As New ReportingService2010()
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim items As CatalogItem() = Nothing
' Retrieve a list of all items from the report server database.
Try
items = rs.ListChildren("/", True)
Catch e As SoapException
MessageBox.Show(e.ToString())
End Try
' Serialize the contents as an XML document and write the contents to a file.
Try
Dim fs As New FileStream("ReportNames.xml", FileMode.Create)
Dim writer As New XmlTextWriter(fs, Encoding.Unicode)
Dim serializer As New XmlSerializer(GetType(CatalogItem())) ''
serializer.Serialize(writer, items)
'MessageBox.Show("Report names successfully written to a file.")
writer.Close()
Catch e As Exception
MessageBox.Show(e.ToString())
End Try
End Sub
我可以将 XML 文件读入 VB.net 数据集:
公共子文件到数据集()
' Serialize the contents as a Dataset
Dim myXMLfile As String = "C:\MyFile.xml"
Dim ds As New DataSet()
' Create new FileStream with which to read the schema.
Dim fsReadXml As New System.IO.FileStream(myXMLfile, FileMode.Open)
ds.ReadXml(fsReadXml)
结束子
对于我的项目,我从获取报告名称开始,然后继续获取每个报告的参数,然后继续调用报告。我为每个步骤提供了简单的示例代码,但目前这一切都涉及写入磁盘上的 XML 文件......
编辑:看起来我应该能够从 CatalogItem 做我需要做的事情。基本上我想将报告名称加载到 TreeView 中,所以 CatalogItem 应该没问题。