Crystal Reports Experts - Need some help

brandonbull

Diamond Member
May 3, 2005
6,365
1,223
126
I'm trying to determine if it's possible to pass parameters to a Crystal Report that is set up as a web service. I'm using CRBasic for VS2008.

I'm able to pass parameters to reports that are embedded within our ASP.Net app.

I was trying to publish individual reports as a web service and then have the main app pass parameter values to the web service and then the main app consume the web service. I can get the app to consume none parameterized report services but no luck on the parameter part. The only answers I get are from people that do not read the question and then post the answer to passing parameters to a report.
 

imported_Dhaval00

Senior member
Jul 23, 2004
573
0
0
Crystal Reports (CR) has an event, I believe, OnInitReport(). What you want to do is in your host app, create a CookieContainer to hold the parameters as cookies. Then, when the WS call is made, use the OnInitReport() event on the server to access those cookies/parameters via HttpContext.Current.Request.Cookies. Finally, use these values to set the boundaries on your data set. As a side note, the WS proxy in .NET automatically exposes a CookieContainer property that you can use to populate the cookies.

See if this helps.


PS: It has been ages since I last used Crystal Reports (pile of crap). So there could be better ways to achieve this.
 

brandonbull

Diamond Member
May 3, 2005
6,365
1,223
126
The problem I'm trying to work around is having the reports in the app and reducing the frequency that the entire app would need to be redeployed even for a minor change to a report.

I'm not a big fan of our current reporting structure but I came on board to help with reporting after the app was built.

This web service should be able to accept parameters like you can to other web services.
 

imported_Dhaval00

Senior member
Jul 23, 2004
573
0
0
Then why not simply use Reporting Services? It is way better than Crystal Reports, definitely faster, has scheduled reports, and a whole bunch of others things that go beyond viewing simple, static reports.
 

brandonbull

Diamond Member
May 3, 2005
6,365
1,223
126
I've talked my boss into pushing for SQL Server 2008 but I have make a presentation on why we should migrate to sql server w/ reporting services and away from Crystal.

I wasn't even originally brought in to the company for reporting but since I have had some crystal reporting experience and .net dev experience they tasked me to develop a reporting solution with crystal. They had the licenses for crystal but no one that could build and integrate it into a asp.net app.

I guess I fell into being the reporting manager/report writer/reporting data warehouse architect by default.

Until we can get SS in place, I have to try and improve the current state of reporting. If we need to make a change, it currently takes 2 weeks to get changes moved into production because reports are embedded into the app. I was trying to develop reports as web services and move them outside of the app so we can speed up the production delivery of report changes.
 

brandonbull

Diamond Member
May 3, 2005
6,365
1,223
126
<%@ webservice language="VB" class="webservicetestService" %>

Imports System
Imports System.Web.Services
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.Web.Services

< WebService( Namespace:="http://crystaldecisions.com/reportwebservice/9.1/" ) > _
Public Class webservicetestService
Inherits ReportServiceBase

'Public Sub New(ByVal ParmName As String, ByVal ParmValue As String)
Public Sub New()
Dim crReport As New ReportDocument
crReport.Load(Me.Server.MapPath("webservicetest.rpt"), OpenReportMethod.OpenReportByDefault)
crReport.SetParameterValue("pTest", "Espresso")
Me.ReportSource = crReport 'Me.Server.MapPath("webservicetest.rpt")
End Sub

End Class


I was able use hardcoded parameters in the webservice to get the report to filter records. I just need to figure out how to pass parameters from my app to the webservice.
 

imported_Dhaval00

Senior member
Jul 23, 2004
573
0
0
Use the strategy I mentioned in my first post, dude.

Something like the following:

Cookie myCookie = new Cookie( "Name", "brandon", "/", "localhost");
CookieContainer myContainer = new CookieContainer();
myContainer.Add(myCookie);

ReportService crystal = new ReportService();
crystal.CookieContainer = myContainer;
CrystalReportViewer1.ReportSource = crystal;


On the server side, make sure you import System.Web and override the OnInitReport() event (I don't remember the name off the top of my head). Then, to access the cookie do the following:

HttpCookieCollection myCookies = HttpContext.Current.Request.Cookies;
// Assumes myReport is your Crystal Report instantiation
myReport.SetParameterValue(myCookies["Name"].Value;


I'll let you interpret the C# code.
 

brandonbull

Diamond Member
May 3, 2005
6,365
1,223
126
Do you have a workaround for being able to print the drilldown levels from Crystal?