Making Server Side Report Modifications
The last section showed how the client is limited to using the viewer control for making runtime modifications. This doesn’t give you many options for making runtime modifications. But that doesn’t mean that it is impossible to make changes using the ReportDocument class. You just have to do it on the server within the web service application.
Making changes on the server side is very powerful because you get full access to the ReportDocument class. You can make changes to the report objects so that the report is completely dynamic. And you don’t have to learn any new coding practices because you can use same code shown throughout this book. The only difference is how you reference the ReportDocument object. That is the tricky part!
Before showing you how to make server side modifications, you need to understand that there is one major problem with this approach. The server can’t communicate with the client because the client can’t pass information to the report web service. If this were a typical application, the user would enter information on a form and this information is used to modify the ReportDocument object prior to printing the report. But you can’t do this with report web services. If you try to pass information on the query string, the web service returns an error. You also can’t use cookies because these are strictly client based. You are restricted to making changes to the ReportDocument object that aren’t user specific.
The one trick around this is to use multiple web services that open the same report. Each web service can perform a different modification to the report object prior to previewing it. For example you could have one web service show the default report and another web service modify the default grouping of a report. This lets one report be used by different web services and the end user thinks that they are looking at different reports. As another example, you could also have different web services specific to individual clients. Each client gets the same report, but you can charge them an additional fee if they want it customized to match their corporate image.
Modifying the ReportDocument object is done by overwriting the existing code in the instantiator method. For VB.NET, this is the New() method. It is within the web service’s underlying .asmx.vb file (.asmx.cs for C# programs).
Here is the New() method code for the EmployeeList web service report that was created earlier in this chapter. It creates a ReportDocument object, loads the Employee List into it, and assigns a new report title to it.
Listing 18-3. Setting report properties on the client
[VB.NET]
Public Sub New()
Dim myReport As new CrystalDecisions.CrystalReports.Engine.ReportDocument
myReport.Load(Server.MapPath("EmployeeListx.rpt"))
myReport.SummaryInfo.ReportTitle = "New Report Title"
Me.ReportSource = myReport
End Sub
[C#]
Public EmployeeListService()
{
CrystalDecisions.CrystalReports.Engine.ReportDocument myReport;
myReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
myReport.Load(Server.MapPath( "EmployeeListx.rpt" ));
myReport.SummaryInfo.ReportTitle = "New Report Title";
this.ReportSource = myReport;
}
Being able to modify the ReportDocument on the server is crucial if you have a report based on a DataSet. If you recall from Chapter 17, datasets have to be manually populated by the application and assigned to the report using the SetDataSource() method of the ReportDocument object. You also know from the previous section that the viewer class can only set login credentials for a report. It can’t set the data source property. If a report uses a dataset and you make it into a web service, the viewer is going to give you an error.