ActiveReports for .NET 3 Online Help Request technical support
ActiveReports Document Web Service
See Also
User Guide > Samples and Walkthroughs > Walkthroughs > Standard Edition Walkthroughs > Advanced > Web Walkthroughs (Standard Edition) > Web Services Walkthroughs > ActiveReports Document Web Service

Glossary Item Box

With ASP.NET and ActiveReports, you can set up a Web Service that returns a report document which can be shown in a report viewer control.

This walkthrough illustrates how to create a Web Service that returns the contents of an ActiveReport as a byte array.

This walkthrough is split up into the following activities:

To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\Data Dynamics\ActiveReports for .NET 3.0\Data\NWIND.MDB.

You will also need to add a reference to your project to the System.Data.OleDb namespace.

When you have completed this walkthrough, you will have created a Web Service that returns the contents of an ActiveReport as a byte array.

Creating an ASP.NET Web Service project

To create an ASP.NET Web Service project in Visual Studio 2003

  1. From the File menu, select New > Project.
  2. In the Templates window of the New Project dialog, select ASP.NET Web Service.
  3. Change the name of the project from WebService1 to ARDocumentWS.
  4. Click OK to open the new project in Visual Studio. 

To create an ASP.NET Web Service project in Visual Studio 2005

  1. From the File menu, select New > Web Site.
  2. In the Templates window of the New Web Site dialog, select ASP.NET Web Service.
  3. Change the name of the project from WebService1 to ARDocumentWS.
  4. Click OK to open the new project in Visual Studio.

Adding an ActiveReport to the Visual Studio project

To add an ActiveReport to your project

  1. From the Project menu (or Website menu in Visual Studio 2005), select Add New Item.
  2. Select ActiveReports 3.0 File and rename the file rptProducts.
  3. Click Open (or Add in Visual Studio 2005).
To see the report design surface in Visual Studio 2005, right-click the report in the Solution Explorer and select View Designer.

Connecting the data source to a database

To connect the data source to a database

  1. Click the gray report DataSource icon in the Detail section to open the report DataSource dialog.
  2. Click Build.
  3. Select "Microsoft Jet 4.0 OLE DB Provider" and click Next .
  4. Click the ellipsis button to browse for the access path to the Northwind database. Click Open once you have selected the appropriate access path.
  5. Click OK to continue.
  6. In the Query field, type "Select * from products inner join categories on products.categoryid = categories.categoryid order by categoryname".
  7. Click OK to return to the report design surface.

Adding controls to the report to contain data

To add controls to the report

  1. Add a GroupHeader/Footer section to rptProducts by right-clicking on the design surface of the report and selecting Insert > Report Header/Footer.
  2. Make the following changes to the group header:
    • Change the Name property to ghCategories
    • Change the DataField property to CategoryName
    • Change the BackColor property to LightGray
  3. In the Report Explorer, expand the Fields node, then the Bound node. Drag the following fields onto ghCategories and set the properties as indicated. 

    Field Text Location Miscellaneous
    CategoryName CategoryName 1.75, 0  Font size = 14; ForeColor = DarkGreen
  4. Add a second GroupHeader/Footer section to rptProducts to contain labels.
  5. Make the following changes to the group header:
    • Change the Name property to ghProducts
    • Change the BackColor property to WhiteSmoke 
  6. Add labels with the following properties to ghProducts:

    Name Text Location
    lblProductName  Product Name 0, 0 
    lblUnitPrice Unit Price 2.38, 0
    lblUnitsInStock Units in Stock 3.94, 0
    lblUnitsOnOrder Units on Order 5.13, 0
  7. Set the CanShrink property of the detail section to True.
  8. In the Report Explorer, expand the Fields node, then the Bound node. Drag the following fields onto the detail section and set the properties as indicated. 

    Field Text Miscellaneous Location
    ProductName Product Name Size = 2.25, 0,19 0, 0
    UnitPrice Unit Price OutputFormat = Currency 2.38, 0
    UnitsInStock Units In Stock Alignment = Right 3.94, 0
    UnitsOnOrder Units On Order Alignment = Right 5.13, 0

Adding code to create the Web Method

To write the code to create the Web Method

' Visual Basic
<WebMethod( _ Description:="Returns a products report grouped by category")> _ Public Function GetProductsReport() As Byte() Dim rpt As New rptProducts() rpt.Run() Return rpt.Document.Content End Function
//C#
[WebMethod(Description="Returns a products report grouped by category")] public Byte[] GetProductsReport() { rptProducts rpt = new rptProducts(); rpt.Run(); return rpt.Document.Content; }

Testing the Web Service

To test the Web Service

  1. Press F5 to run the project. 
  2. Click "GetProductsReport" in the list of supported operations.
  3. Click the Invoke button to test the Web Service operation.
  4. If the test is successful, you will see the binary version of the contents of rptProducts.

Publishing the Web Service

To publish the Web Service

  1. In the Solution Explorer, right-click the project name and select Publish Web Site
  2. Click the OK button. The Web Service is now available for consumption by other projects.

See Also

©2009. All Rights Reserved.