Quantcast
Channel: SCN : Discussion List - SAP Crystal Reports, version for Visual Studio
Viewing all articles
Browse latest Browse all 3636

how to run a report from WCF

$
0
0

hi,
I am trying to run a report from a WCF service application, and then render it in PDF Format to a caller WPF application. But I cant get it! In more detail, this is what my app should do

1. from WPF, call a web service procedure, pass a report name, report path and parameters. Report is store at the same server where Web Service is installed

2. WCF procedure loads report, set parameters, retrieve data from DB and renders it as an array of bytes

3. WPF gets the array, save it into a PDF file, then open it.


this is the code of the WCF procedure.

    Function DownloadCRReport(codEnte As String, connString As String, reportDir As String, reportName As String, Parameters As Dictionary(Of String, Object)) As Byte() Implements IGesiService.DownloadCRReport

        Try

            Dim bytes As Byte()

            Dim infile As BinaryReader


            Dim fs As FileStream


            Dim rep As New ReportDocument

            Dim RepAddress As String


            logPath = reportDir & "log\"


            sb = New StringBuilder()


            timestamp = Now.Year.ToString & Now.Month.ToString & Now.Day.ToString & Now.Hour.ToString & Now.Minute.ToString & Now.Second.ToString

            logFileName = timestamp & "_" & reportName & ".txt"

            logFile = New StreamWriter(logPath & logFileName, FileMode.CreateNew)


 

            logFile.WriteLine("----


Date and time: " & Now.ToString & " -


")



            If My.Computer.FileSystem.FileExists(reportDir & reportName & ".rpt") = False Then

                Throw New Exception("file RPT non found in: " & reportDir)

            End If


            RepAddress = reportDir & reportName & ".rpt"

            logFile.WriteLine("rep address: " & RepAddress)


            rep.Load(RepAddress, OpenReportMethod.OpenReportByDefault)

            logFile.WriteLine("load rep")


            If rep.DataSourceConnections.Count > 0 Then

                rep.DataSourceConnections.Item(0).SetLogon("usr", "pwd")

                logFile.WriteLine("data source connection")

            End If

            For Each i In Parameters

                rep.SetParameterValue(i.Key, i.Value)

                logFile.WriteLine("param: " & i.Key & " - " & i.Value)

            Next

            Try

                fs = rep.ExportToStream(ExportFormatType.PortableDocFormat)

                logFile.WriteLine("export to stream")

                infile = New BinaryReader(fs)

                logFile.WriteLine("created binaryreader")


                bytes = infile.ReadBytes(CInt(fs.Length))

                logFile.WriteLine("render pdf. fine")

                logFile.Close()

                Return bytes

            Catch ex As Exception

                logFile.WriteLine("vbCrLf & ex.Message & vbCrLf & ex.InnerException.Message)

                logFile.Close()

                Return Nothing

            End Try


        Catch ex As Exception

            logFile.WriteLine("vbCrLf & ex.Message & "-" & vbCrLf & ex.InnerException.Message)

            logFile.Close()

            Return Nothing

        End Try

    End Function


I detected that error occurs on rep.ExportToStream(ExportFormatType.PortableDocFormat). I should point out that the same procedure works under WPF application. In the WCF server I installed CR Runtime engine for .NET framework (13.0.9.1312) and CR version for Microsoft Visual Studio (same version). Moreover, all DB operations are stored into the report, so I should not pass any dataset, just parameters.

Anyway, just to begin, I tried to call a simple report with just two string parameters and no queries, but I alwais get error ("An exception of type 'System.NullReferenceException' occurred in MyApp... Object reference not set to an instance of an object)!

How can I make it work? thanks for help



 


Viewing all articles
Browse latest Browse all 3636

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>