In part 1 of this article we looked at how to create an XML Web service from an existing Crystal Report. In this article, we are going to look at how to consume that Web service from within your own Windows application.
To start, you will need to create a new Windows application within Visual Studio.NET by selecting File > New > Project. In this instance, we are going to create a VB.NET application and call it “ConsumeWebService”.
Once you have created your new project, a default form will be created (Form1) and we are going to use this form to display the report served up by your Web service. The first thing we need to do is to drag and drop the Crystal Report viewer onto your form.
In the toolbox, select the section marked “Windows Forms” and locate the icon marked CrystalReportViewer. Click this icon and then use your mouse to draw the Crystal Report Viewer onto your form in the size and shape you want.
Note: You also may want to set the DOCK property of the viewer to “Fill” so it will fill the entire form when the project is compiled and run
Next, we need to set the let the viewer know where to retrieve the report, which we will do in the Form1_Load subroutine. The viewer that you added to your form will be called “CrystalReportViewer1” by default and there is a “ReportSource” property that you can set to tell the viewer where to get the report. In this case, it is the Web service we created in part 1 of this article, as shown in the code below:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CrystalReportViewer1.ReportSource = “http://localhost/ReportService/World%20Sales%20ReportService.asmx”
Note: Since the report name originally had spaces in it, the spaces in the URL have been replaced with escape characters (%20).
This is the only line of code you need to make this solution workÃÂ¢Ã¢,Â¬”when you compile and run your application, the report displayed in the viewer will be retrieved from the Web service.
And this is just a simple exampleÃÂ¢Ã¢,Â¬”you could also consume reporting Web services from ASP, ASP.NET and COM Web applications, as well as Windows applications and any development environment that supports the Crystal Reports Viewer.
Subscribe to the Daily Tech Insider Newsletter
Stay up to date on the latest in technology with Daily Tech Insider. We bring you news on industry-leading companies, products, and people, as well as highlighted articles, downloads, and top resources. You’ll receive primers on hot tech topics that will help you stay ahead of the game. Delivered Weekdays