Friday 24 February 2012

Conflicting docs on how to render

I am trying to use the render method to render to a byte array in an ASP.Net application and I am having a problem in that there is a lot of conflicting information in the books and the docs on how to do this. The latest docs I read led to the following code...

ReportingService2005 _rs = new ReportingService2005();

//have to use custom credentials because ASPNET does not have sufficient authority...
NetworkCredential myCred = new NetworkCredential("myuserid", "mypassword", "mydomain");
CredentialCache myCash = new CredentialCache();
myCash.Add(new Uri("http://localhost/myWebSiteName"), "NTLM", myCred);
_rs.Credentials = myCash;
_rs.Url = "http://localhost/ReportServer/ReportService2005.asmx";

//we just have one parameter...
ParameterValue[] Parameters = new ParameterValue[1];
Parameters[0].Name = "myReportID";
Parameters[0].Value = argmyReportID;

//Render the report to a byte array...
byte[] data;
data = _rs. oops there is no Render method!!

The first docs I read (WROX BOOK on SSRS2005) said to use the ReportingService class but there is no such class. I then found docs saying to use ReportingService2005 class as I did above. But that class has no Render method. Today I found other docs that say to use ReportExecutionService class.

Why are there so many conflicting docs. What class am I supposed to use to do a render?

Thanks,
Gary

This one here worked for me:

ReportServices.ReportingService rs = new ReportServices.ReportingService();

rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

byte[] ResultStream; // bytearray for result stream

string[] StreamIdentifiers; // string array for stream idenfiers

string OptionalParam = null; // string out param for optional parameters

ReportServices.ParameterValue[] optionalParams = null; // parametervalue array for optional parameters

ReportServices.Warning[] optionalWarnings = null; // warning array for optional warnings

ResultStream = rs.Render("/ReportProject1/Report1", "HTML4.0", null,

"<DeviceInfo><StreamRoot>/RSWebServiceXS/</StreamRoot></DeviceInfo>", null, null,

null, out OptionalParam, out OptionalParam, out optionalParams,

out optionalWarnings, out StreamIdentifiers);

After creating a webServices proxy class on ReportService.asmx.

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

|||

I get an error on

ResultStream = rs.Render(My.Settings.ReportPath, "PDF", Nothing, "<DeviceInfo><StreamRoot>/RSWebServiceXS/</StreamRoot></DeviceInfo>", Nothing, Nothing, _

Nothing, OptionalParam, OptionalParam, optionalParams, _

optionalWarnings, StreamIdentifiers)

it says that "render" is not a member of reportService. any ideas?

|||Which WebService (*.asmx) did you reference ?

HTH, Jens K. Suessmeyer.


http://www.sqlserver2005.de

|||

I am using both the reportExecution and ReportService. After struggling with it for a while I went and looked at the renderand save sample that someone had pointed out earlier. This time the code actually worked with some minor modifications. I am posting the whole code routine below in case someone has the same issue in the future.

Public Sub ExportToDisk()

Dim strFileName As String = System.Windows.Forms.Application.StartupPath

Dim strAppPath As String = System.Windows.Forms.Application.StartupPath

Try

Dim rs As New ReportExecutionService()

rs.Credentials = System.Net.CredentialCache.DefaultCredentials

rs.Url = My.Settings.EmailInvoices_ReportExecution_ReportExecutionService

Dim result As Byte() = Nothing

Dim reportPath As String = My.Settings.ReportPath

Dim format As String = "PDF"

Dim historyID As String = Nothing

Dim devInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"

' Prepare report parameter.

Dim parameters(0) As ReportExecution.ParameterValue

parameters(0) = New ReportExecution.ParameterValue()

parameters(0).Name = "InvoiceNumber"

parameters(0).Value = Me.Invoice

Dim credentials As ReportExecution.DataSourceCredentials() = Nothing

Dim showHideToggle As String = Nothing

Dim encoding As String = ""

Dim mimeType As String = ""

Dim warnings As ReportExecution.Warning() = Nothing

Dim reportHistoryParameters As ReportExecution.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(reportPath, historyID)

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

SessionId = rs.ExecutionHeaderValue.ExecutionID

Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID)

Try

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

execInfo = rs.GetExecutionInfo()

Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime)

Catch e As System.Exception

Console.WriteLine(e.ToString)

End Try

' Try

Using stream As FileStream = File.OpenWrite(strFileName & "\EmailFiles\" & Me.Invoice & ".PDF")

stream.Write(result, 0, result.Length)

stream.Close()

stream.Dispose()

End Using

Catch e As Exception

Console.WriteLine(e.Message)

End Try

Catch e As System.Exception

MessageBox.Show(e.Message)

End Try

End Sub

|||

I am using both the reportExecution and ReportService. After struggling with it for a while I went and looked at the renderand save sample that someone had pointed out earlier. This time the code actually worked with some minor modifications. I am posting the whole code routine below in case someone has the same issue in the future.

Public Sub ExportToDisk()

Dim strFileName As String = System.Windows.Forms.Application.StartupPath

Dim strAppPath As String = System.Windows.Forms.Application.StartupPath

Try

Dim rs As New ReportExecutionService()

rs.Credentials = System.Net.CredentialCache.DefaultCredentials

rs.Url = My.Settings.EmailInvoices_ReportExecution_ReportExecutionService

Dim result As Byte() = Nothing

Dim reportPath As String = My.Settings.ReportPath

Dim format As String = "PDF"

Dim historyID As String = Nothing

Dim devInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"

' Prepare report parameter.

Dim parameters(0) As ReportExecution.ParameterValue

parameters(0) = New ReportExecution.ParameterValue()

parameters(0).Name = "InvoiceNumber"

parameters(0).Value = Me.Invoice

Dim credentials As ReportExecution.DataSourceCredentials() = Nothing

Dim showHideToggle As String = Nothing

Dim encoding As String = ""

Dim mimeType As String = ""

Dim warnings As ReportExecution.Warning() = Nothing

Dim reportHistoryParameters As ReportExecution.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(reportPath, historyID)

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

SessionId = rs.ExecutionHeaderValue.ExecutionID

Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID)

Try

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

execInfo = rs.GetExecutionInfo()

Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime)

Catch e As System.Exception

Console.WriteLine(e.ToString)

End Try

' Try

Using stream As FileStream = File.OpenWrite(strFileName & "\EmailFiles\" & Me.Invoice & ".PDF")

stream.Write(result, 0, result.Length)

stream.Close()

stream.Dispose()

End Using

Catch e As Exception

Console.WriteLine(e.Message)

End Try

Catch e As System.Exception

MessageBox.Show(e.Message)

End Try

End Sub

|||

I am using both the reportExecution and ReportService. After struggling with it for a while I went and looked at the renderand save sample that someone had pointed out earlier. This time the code actually worked with some minor modifications. I am posting the whole code routine below in case someone has the same issue in the future.

Public Sub ExportToDisk()

Dim strFileName As String = System.Windows.Forms.Application.StartupPath

Dim strAppPath As String = System.Windows.Forms.Application.StartupPath

Try

Dim rs As New ReportExecutionService()

rs.Credentials = System.Net.CredentialCache.DefaultCredentials

rs.Url = My.Settings.EmailInvoices_ReportExecution_ReportExecutionService

Dim result As Byte() = Nothing

Dim reportPath As String = My.Settings.ReportPath

Dim format As String = "PDF"

Dim historyID As String = Nothing

Dim devInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"

' Prepare report parameter.

Dim parameters(0) As ReportExecution.ParameterValue

parameters(0) = New ReportExecution.ParameterValue()

parameters(0).Name = "InvoiceNumber"

parameters(0).Value = Me.Invoice

Dim credentials As ReportExecution.DataSourceCredentials() = Nothing

Dim showHideToggle As String = Nothing

Dim encoding As String = ""

Dim mimeType As String = ""

Dim warnings As ReportExecution.Warning() = Nothing

Dim reportHistoryParameters As ReportExecution.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(reportPath, historyID)

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

SessionId = rs.ExecutionHeaderValue.ExecutionID

Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID)

Try

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

execInfo = rs.GetExecutionInfo()

Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime)

Catch e As System.Exception

Console.WriteLine(e.ToString)

End Try

' Try

Using stream As FileStream = File.OpenWrite(strFileName & "\EmailFiles\" & Me.Invoice & ".PDF")

stream.Write(result, 0, result.Length)

stream.Close()

stream.Dispose()

End Using

Catch e As Exception

Console.WriteLine(e.Message)

End Try

Catch e As System.Exception

MessageBox.Show(e.Message)

End Try

End Sub

No comments:

Post a Comment