Rending Reports from VB Application
I am using Visual Studio 2008, and have added Web Reference named ReportingService to the project. When I click the button, it compiles without any errors, but does not render any reports to specified folder. #Region " Properties " Public Property ReportPath() As String Get Return Me.m_sReportPath End Get Set(ByVal Value As String) Me.m_sReportPath = Value End Set End Property Public Property FilePath() As String Get Return Me.m_sFilePath End Get Set(ByVal Value As String) Me.m_sFilePath = Value End Set End Property #End Region #Region " Constructors " #End Region #Region " Declarations " 'File types to export to 'HTML 3.2 and 4.0 were removed for simplicity's sake Public Enum ReportExportFileType XML NULL CSV IMAGE PDF MHTML EXCEL HTMLOWC End Enum Private Params As New Hashtable Private m_sReportPath As String = String.Empty Private m_sFilePath As String = String.Empty #End Region #Region " Functions " Public Function Render( _ ByVal Format As String) End Function Private Function LoadParams() As ReportingService.ParameterValue() Dim array(Params.Count - 1) As ReportingService.ParameterValue Dim i As Integer = 0 'Since the Parameter array uses a key-value pair, use a DictionaryEntry to hold the necessary information to construct the parameter array For Each de As DictionaryEntry In Params Dim pValue As New Parameter pValue.Name = de.Key.ToString() pValue.Value = de.Value.ToString() array(i) = pValue i += 1 Next Return array End Function Public Function ExportReport(ByVal outputFormat As ReportExportFileType) As Boolean 'Renders the report to the file type specified by outputFormat 'Requires the ReportPath() and FilePath() properties to be set prior to the function call Dim objReportingService As ReportingService.ReportingService2005 Dim Render As String Dim ReportExecutionService As Object Dim results As Byte() Dim fs As System.IO.FileStream Dim sOutputFormat As String = outputFormat.ToString() 'REQUIRED for method call - but not used Dim DeviceInfo As String = Nothing Dim HistoryId As String = Nothing Dim ShowHideToggle As String = Nothing Dim RSCredentials As DataSourceCredentials() = Nothing 'OUTPUT variables Dim RSParamsUsed As Parameter() Dim RSWarnings As Warning() Dim Encoding As String Dim MimeType As String Dim StreamIds As String() Try objReportingService = New ReportingService.ReportingService2005 objReportingService.Url = "http://gmcisvc01/reportserver/ReportService2005.asmx" 'This maps to the location of the ReportingServices Web Service; available (by default) in the reportserver folder on your Report Server objReportingService.Timeout = 600000 'Report will run up to ten minutes before timing out objReportingService.Credentials = System.Net.CredentialCache.DefaultCredentials 'Renders the report to the results byte array results = ReportExecutionService.render(m_sReportPath, sOutputFormat, HistoryId, DeviceInfo, LoadParams(), _ RSCredentials, ShowHideToggle, Encoding, MimeType, RSParamsUsed, RSWarnings, StreamIds) 'Delete any existing file with the same file name System.IO.File.Delete(m_sFilePath) 'Write to the specified file fs = System.IO.File.OpenWrite(m_sFilePath) fs.Write(results, 0, results.Length) fs.Close() objReportingService.Dispose() objReportingService = Nothing 'GC.Collect() Return True Catch ex As Exception ' Catch the error. Beep() Finally objReportingService = Nothing results = Nothing fs = Nothing 'GC.Collect() End Try End Function Public Sub AddParameter(ByVal name As String, ByVal value As Object) Params.Add(name, value) End Sub #End Region 'Next, from wherever the event that triggers the export is located, you need 'to create the Exporter object and set it's parameters, then call the 'ExportReport function to render the report: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim exportSucceeded As Boolean Call LoadParams() 'Prepare the report for exporting 'The ReportingServiceExporter FilePath and ReportPath properties MUST be set before exporting Dim exporter As New NewProspectBatchLoadTDSP 'Target output file path - change the extension to whatever format you need to export to exporter.FilePath = "C:\temp\FixedTemplate.pdf" 'Path to the report on the server, starting from //REPORTSERVER/reportserver, where the web reference inside the ReportingServiceExporter is loaded from; make sure you don't type the .rdl extension exporter.ReportPath = "http://gmcisvc01/Reportserver/Contracts/FixedTemplate" 'Next, simply add the parameters that the report requires exporter.AddParameter("ProspectID", 22020) exporter.AddParameter("DealCapID", 28144) 'exporter.AddParameter("Param3", value) 'Finally, call the ExportReport method with the enumerated type of the format exportSucceeded = exporter.ExportReport(NewProspectBatchLoadTDSP.ReportExportFileType.PDF) End Sub
December 13th, 2010 12:20pm

Hi Natongm, I notice the web service end point you used in the code is ReportService2005. However, in a matter of fact, in order to render a report using the SQL Server Reporting Services(SSRS) web services, we need to use the ReportExecution2005. So, please change the following code to solve the issue: From: objReportingService = New ReportingService.ReportingService2005 objReportingService.Url = "http://gmcisvc01/reportserver/ReportService2005.asmx" 'This maps to the location of the ReportingServices Web Service; available (by default) in the reportserver folder on your Report Server To: objReportingService = New ReportingService.ReportExecutionService objReportingService.Url = "http://gmcisvc01/reportserver/ReportExecution2005.asmx" 'This maps to the location of the ReportingServices Web Service; available (by default) in the reportserver folder on your Report Server Also, please add the web service reference to http://gmcisvc01/reportserver/ReportExecution2005.asmx instead of http://gmcisvc01/reportserver/ReportService2005.asmx. For more information about ReportExecution2005, please see: http://msdn.microsoft.com/en-us/library/reportexecution2005.aspx If you have any more questions, please feel free to ask. Thanks, Jin ChenJin Chen - MSFT
Free Windows Admin Tool Kit Click here and download it now
December 15th, 2010 3:45am

Hi Natongm, I notice the web service end point you used in the code is ReportService2005. However, in a matter of fact, in order to render a report using the SQL Server Reporting Services(SSRS) web services, we need to use the ReportExecution2005. So, please change the following code to solve the issue: From: objReportingService = New ReportingService.ReportingService2005 objReportingService.Url = "http://gmcisvc01/reportserver/ReportService2005.asmx" 'This maps to the location of the ReportingServices Web Service; available (by default) in the reportserver folder on your Report Server To: objReportingService = New ReportingService.ReportExecutionService objReportingService.Url = "http://gmcisvc01/reportserver/ReportExecution2005.asmx" 'This maps to the location of the ReportingServices Web Service; available (by default) in the reportserver folder on your Report Server Also, please add the web service reference to http://gmcisvc01/reportserver/ReportExecution2005.asmx instead of http://gmcisvc01/reportserver/ReportService2005.asmx. For more information about ReportExecution2005, please see: http://msdn.microsoft.com/en-us/library/reportexecution2005.aspx If you have any more questions, please feel free to ask. Thanks, Jin ChenJin Chen - MSFT
December 15th, 2010 3:45am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics