You can use a Web Service that returns a dataset as the data source for your reports in Windows applications. This walkthrough illustrates how to create a Windows client application that uses the dataset Web Service as the data source for an ActiveReport.
This walkthrough builds on the DataSet Web Service walkthrough and is split up into the following activities:
- Adding controls to a report
- Adding a reference to a Web service to the project
- Setting the report data source to the one returned by the Web service
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 add controls to a report
- Add a new ActiveReport to a Windows application.
- Add the following controls to the Detail section of the report, setting their properties as indicated:
Detail section controls
Control |
DataField |
Miscellaneous |
Location |
Textbox |
ProductName |
Size = 2.9, 0.19 |
0, 0 |
Textbox |
UnitPrice |
OutputFormat = Currency |
3, 0 |
- Set the CanShrink property of the Detail section to True.
To add a reference to a web service to the project
To add a reference to a web service in Visual Studio 2005
- From the Project menu, select Add Web Reference.
- In the Add Web Reference window that appears, click the Web services on the local machine link.
- Click the link to the virtual directory you created in the previous walkthrough. You can get the address by running the project from the previous walkthrough and copying the url from the address in the browser. (It will look something like http://localhost:####/DataSetWS/Service.asmx where #### is the port number.)
- Click the Go button, and then 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 Advanced button.
- In the Service Reference Settings window that appears, click Add Web Reference button.
- In the Add Web Reference window that appears, click the Web services on the local machine link.
- Click the link to the virtual directory you created in the previous walkthrough. You can get the address by running the project from the previous walkthrough and copying the url from the address in the browser. (It will look something like http://localhost:####/DataSetWS/Service.asmx where #### is the port number.)
- Click the Go button, and then 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
- From the Project menu, select Add Service Reference.
- In the Add Service Reference window that appears, type in the address of the virtual directory you created in the previous walkthrough. You can get the address by running the project from the previous walkthrough and copying the url from the address in the browser. (It will look something like http://localhost:####/DataSetWS/Service.asmx where #### is the port number.)
- Click the Go button, and then click the OK button when the Web Service is recognized.
To set the report data source to the one returned by the Web service
To set the report data source (for Visual Studio 2005 and Visual Studio 2008 or 2010 compatible with .NET Framework 2.0 Web service)
- Double-click the gray area below the report. This creates an event-handling method for the ReportStart event.
- Add code to the handler to use the web service dataset in the report.
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 ReportStart event |
Copy Code |
Dim ws As New localhost.Service
Dim ds As DataSet()= ws.GetProduct()
Me.DataSource = ds
Me.DataMember = "Products" |
To write the code in C#
C# code. Paste INSIDE the ReportStart event. |
Copy Code |
localhost.DataSetWS ws = new localhost.Service;
DataSet ds = ws.GetProduct();
this.DataSource = ds;
this.DataMember = "Products"; |
To set the report data source (for Visual Studio 2008 or 2010)
- Double-click the gray area below the report. This creates an event-handling method for the ReportStart event.
- Add code to the handler to use the web service dataset in the report.
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 ReportStart event. |
Copy Code |
Dim ws As New ServiceReference1.ServiceSoapClient()
Dim ds As DataSet = ws.GetProduct()
Me.DataSource = ds
Me.DataMember = "Products" |
To write the code in C#
C# code. Paste INSIDE the ReportStart event. |
Copy Code |
ServiceReference1.ServiceSoapClient ws = new ServiceReference1.ServiceSoapClient();
DataSet ds = ws.GetProduct();
this.DataSource = ds;
this.DataMember = "Products"; |
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.