Monday, April 25, 2011

Accessing SSRS throught Web Services

Hi,

This is a simple article explaining how to run reports off SQL server through WebServices.
Please take a look at the example and Ask questions if necessary. It is truly a simple process.

Imports System.IO Imports WEBWMS.ReportExecutionService   Public Class ReportingServices     Dim rsExec As New WEBWMS.ReportExecutionService.ReportExecutionService       Public Sub GenReport(ByVal FolderName As String, ByVal ReportName As String, ByVal ReportParameters As ParameterValue())         ' setup report connection         Dim deviceInfo As String = Nothing         Dim extension As String = [String].Empty         Dim mimeType As String = [String].Empty         Dim encoding As String = [String].Empty         Dim warnings As Warning() = Nothing         Dim streamIDs As String() = Nothing         Dim historyId As String = Nothing         Dim ExecHeader As New ExecutionHeader         Dim TrustUserHeader As New TrustedUserHeader         Dim Results As [Byte]() = Nothing         Dim ExecInfo As ExecutionInfo = New ExecutionInfo         Dim ServInfo As ServerInfoHeader = New ServerInfoHeader           My.User.InitializeWithWindowsUser()         rsExec.ExecutionHeaderValue = ExecHeader         rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials         rsExec.Url = "http://Wedge/reportserver/reportexecution2005.asmx"         ' pass parameters         rsExec.LoadReport("/" & FolderName & "/" & ReportName, historyId)         If ReportParameters.Count = 0 Then         Else             rsExec.SetExecutionParameters(ReportParameters, "en-us")         End If         ' get pdf of report          Results = rsExec.Render("PDF", deviceInfo, extension, mimeType, encoding, warnings, streamIDs)         PrintReport(Results)     End Sub       Private Sub PrintReport(ByVal Data As Byte())         Dim Path As String = "C:\Temp\Reference" & Date.Now.Millisecond.ToString & ".PDF"         Dim LabelFile As FileStream = New FileStream(Path, FileMode.Create)         LabelFile.Write(Data, 0, Data.Length)         LabelFile.Close()         RawPrinterHelper.SendFileToPrinter(My.Settings.UserLaserPrinter, Path)     End Sub End Class 

No comments:

Post a Comment