0

编辑:为清楚起见更新了问题:我需要在内存中将 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 应该没问题。

4

1 回答 1

0

因此,正如您在此处看到的,答案是将 SSRS 报告以 Byte 类型呈现给 result(),移至 MemoryStream,然后将流读取到您的数据集中。也许有人可以让这个例子更简单,我把它从非常复杂的东西中提取出来。

Public Sub fillADatasetFromRdl

Const ReportName As String = "My Report Name"
Private _reportNamePath As String = "/Optional SSRS Directory/" + ReportName
Private _formatXml As String = "XML"


' Prepare report parameter lists. 
Private parametersRdl(4) As ParameterValue

    ' Set RDL parameters
parametersRdl(0) = New ParameterValue()
parametersRdl(0).Name = "StartDate"
parametersRdl(0).Value = "[Current Date].[YearMonthDate].[Month].&[2012-10-01T00:00:00]"

parametersRdl(1) = New ParameterValue()
parametersRdl(1).Name = "EndDate"
parametersRdl(1).Value = "[Current Date].[YearMonthDate].[Month].&[2012-12-01T00:00:00]"

parametersRdl(2) = New ParameterValue()
parametersRdl(2).Name = "ProvidersProviderLocation"
parametersRdl(2).Value = "[Stores].[Store Location].[Stores].&[123456]" 

parametersRdl(3) = New ParameterValue()
parametersRdl(3).Name = "ProviderGroupName"
parametersRdl(3).Value = "Enterprise Report"

' Load dev dataset
Dim devDataSet As New DataSet

Dim rs As New ReportExecutionService
rs.Credentials = System.Net.CredentialCache.DefaultCredentials

' Render arguments
Dim result As Byte() = Nothing
Dim historyID As String = Nothing
Dim devInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"

Dim encoding As String = ""
Dim mimeType As String = ""
Dim warnings As shpdevdb01_Execution_Service.Warning() = Nothing
Dim reportHistoryParameters As MyServer_Management_Service.ParameterValue() = Nothing
Dim streamIDs As String() = Nothing

Dim execInfo As New ExecutionInfo()
Dim execHeader As New ExecutionHeader()
Dim SessionId As String
Dim extension As String = ""

rs.ExecutionHeaderValue = execHeader

execInfo = rs.LoadReport(reportNamePath, historyID)


rs.SetExecutionParameters(parameters, "en-us")

SessionId = rs.ExecutionHeaderValue.ExecutionID

Try
    result = rs.Render(format, devInfo, extension, _
       encoding, mimeType, warnings, streamIDs)

    execInfo = rs.GetExecutionInfo()

    Dim bytes() As Byte = result
    Dim s As New System.IO.MemoryStream(bytes)
    dsDevData.ReadXml(s)

Catch e1 As SoapException

End Try


Catch e As Exception
End Try

End Sub
于 2013-10-16T23:04:36.907 回答