ActiveReports 6 Online Help
Document Web Service

Show AllShow All
Hide AllHide All

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\GrapeCity\ActiveReports 6\Data\NWIND.MDB (on a 64-bit operating Windows system, a copy is located in C:\Program Files (x86)\GrapeCity\ActiveReports 6\Data\NWIND.MDB).

You must also add a reference in your project to the System.Data.OleDb namespace.

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

To create an ASP.NET Web Service project

  1. From the Visual Studio File menu, select New, then 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 WebSite1 to ARDocumentWS.
  4. Click OK to open the new project in Visual Studio.

To add a report and connect it to data

  1. From the Website menu, select Add New Item.
  2. Select ActiveReports 6 (code-based) File, rename it rptProducts, and click the Add button.
  3. In the message box that appears, click the Yes button to place the report inside the App_Code folder. Instead of the design view, the code view of the report opens.
  4. To go to the design view of the report, in the Solution Explorer, right-click rptProducts and select View Designer.
  5. Click the gray report DataSource icon on the Detail section band to open the Report Data Source dialog.
  6. On the OLE DB tab, next to Connection String, click the Build button.
  7. In the Data Link Properties window that appears, select Microsoft Jet 4.0 OLE DB Provider and click the Next button.
  8. Click the ellipsis (...) button to browse to the Northwind database. Click Open once you have selected the appropriate access path.
  9. Click OK to close the window and fill in the Connection String field.
  10. In the Query field, enter the following SQL query
    SQL Query
    Copy Code
    SELECT * FROM Products INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID ORDER BY CategoryName
  11. Click OK to save the data source and return to the report design surface.

To add controls to the report

  1. Right-click on the design surface of the report and select Insert, then Group Header/Footer to add a group header and group footer section.
  2. Click to select the group header section, and in the Properties window, make the following changes:
    • 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.
  4. Drag the following field onto ghCategories and set the properties as indicated.

    Field for ghCategories

  5. Add a second GroupHeader/Footer section to the report to contain labels.
  6. Make the following changes to the new group header:
    • Change the Name property to ghProducts
    • Change the BackColor property to WhiteSmoke
  7. Add labels with the following properties to ghProducts:

    Labels for ghProducts

  8. Set the CanShrink property of the detail section to True.
  9. From the Report Explorer, drag the following fields onto the detail section and set the properties as indicated.

Controls for the detail section

To write the code to create the Web Method

  1. On the Service.vb or Service.cs tab is the code view of the Service.asmx file.
  2. Replace the existing WebMethod and HelloWorld function with the following code.

To write the code in Visual Basic.NET

To write the code in C#

To test the Web Service

  1. Press F5 to run the project. The Service page appears in your browser.
  2. In the list of supported operations at the top, click GetProductsReport.
  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.

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.

To create a virtual directory in Internet Information Services

  1. In Windows Explorer, navigate to the folder containing your Web service folder.
  2. Right-click the folder and select Sharing and Security.
  3. On the Web Sharing tab, select the Share this folder radio button.
  4. Click the OK button to save the setting and close the window.

To create a virtual directory in IIS 7.x

  1. In the Control Panel, open Administrative Tools, then Internet Information Services Manager.
  2. In the Internet Information Services Manager window that appears, expand the tree view in the left pane until you see the Web Site you need to create a virtual directory for.
  3. Right-click the node for the Web Site and select Add Application…
  4. In the Add Application dialog box that appears, enter the following information:

    Alias: enter a name for the virtual directory.

    Physical path: select the folder that contains your Web service folder.

  5. Click the OK button to save the settings and close the window.
Important: In order to consume Web services in your Windows applications, you must set permissions to allow the ASP.NET user to consume the services. Ask your server administrator for help with this.

For information on consuming the Document Web Service in a viewer, see Document Windows Application.

See Also