In ActiveReports 6, you can use a Web Service that returns the content of an ActiveReport to show in the Windows Forms viewer control.
This walkthrough illustrates how to create a Windows client application that returns the content of an ActiveReport in the Windows Forms viewer.
This walkthrough builds on the Document Web Service walkthrough and is split up into the following activities:
- Creating a Visual Studio project
- Adding the ActiveReports Windows Forms viewer control to the form
- Adding a reference to a Web service to the project
- Displaying the content returned by the Document Web Service in the viewer
- Running the project
To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\GrapeCity\ActiveReports 6\Data\NWIND.MDB (on a 64-bit Windows operating system, a copy is located in C:\Program Files (x86)\GrapeCity\ActiveReports 6\Data\NWIND.MDB).
When you have finished this walkthrough, you will have a report that looks similar to the following.
To create a Visual Studio project
- From the File menu, select New, then Project.
- In the Templates section of the New Project dialog, select Windows Application.
- Change the name of the application to ARDocumentClient.
- Click OK to open the project.
To add the ActiveReports viewer control
- From the Visual Studio toolbox, drag the ActiveReports Viewer control onto the form.
- Change the Dock property for the viewer control to Fill, and resize the form to accommodate a report.
To add a web reference
To add a reference to a web service in Visual Studio 2005
- From the Project menu, select Add Web Reference.
- Type in the address of the .asmx file for the ActiveReports Document Web Service you created in the previous walkthrough. For example: http://localhost/ARDocumentWS/Service.asmx
- Click the Add Reference button when the Web Service is recognized.
To add a reference to a web service in Visual Studio 2008 or 2010 that is compatible with .NET Framework 2.0 Web service
- From the Project menu, select Add Service Reference.
- In the Add Service Reference window that appears, click the Advanced button.
- In the Service Reference Settings window that appears, click Add Web Reference button.
- From the Project menu, select Add Web Reference.
- Type in the address of the .asmx file for the ActiveReports Document Web Service you created in the previous walkthrough. For example: http://localhost/ARDocumentWS/Service.asmx
- Click the Add Reference button when the Web Service is recognized.
To add a reference to a web service in Visual Studio 2008 or Visual Studio 2010
- From the Project menu, select Add Service Reference.
- In the Add Service Reference that appears, type in the address of the .asmx file for the ActiveReports Document Web Service you created in the previous walkthrough. For example: http://localhost/ARDocumentWS/Service.asmx
- Click the Go button, and then click the OK button when the Web Service is recognized.
To display the content returned by the Document Web Service in the viewer
To display the content (for Visual Studio 2005 and Visual Studio 2008 or 2010 compatible with .NET Framework 2.0 Web service)
- Double-click Form1 to create an event-handling method for the Form1_Load event.
- Add code to the handler to display the document Web service content in the viewer.
The following example shows what the code for the method looks like.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Form Load event. |
Copy Code |
Dim ws As New localhost.Service
Me.Viewer1.Document.Content = ws.GetProductsReport()
|
To write the code in C#
C# code. Paste INSIDE the Form Load event. |
Copy Code |
localhost.Service ws = new localhost.Service();
this.viewer1.Document.Content = ws.GetProductsReport();
|
To display the content (for Visual Studio 2008 or 2010)
- Double-click on Form1 to create an event-handling method for the Form1_Load event.
- Add code to the handler to display the document Web service content in the viewer.
The following example shows what the code for the method looks like.
To write the code in Visual Basic.NET
Visual Basic.NET code. Paste INSIDE the Form Load event. |
Copy Code |
Dim ws As New ServiceReference1.ServiceSoapClient() Me.Viewer1.Document.Content = ws.GetProductsReport()
|
To write the code in C#
C# code. Paste INSIDE the Form Load event. |
Copy Code |
ServiceReference1.ServiceSoapClient ws = new ServiceReference1.ServiceSoapClient(); this.viewer1.Document.Content = ws.GetProductsReport();
|
To update the app.config file (Visual Studio 2008 or 2010 project)
|
Note: You need to update the app.config file if you added the Service Reference to the Visual Studio 2008 or 2010 project in the previous section. |
- In the Solution Explorer, open the app.config file.
- In the tag <binding name = "ServiceSoap"...>, set maxBufferSize and maxReceivedMessageSize to some large number, for example, 200500.
- In the next tag <readerQuotas...>, set maxArrayLength to some large number, for example, 60500.
To run the project
- Press F5 to run the project.
See Also