JWS Web Service for Class Datasets

  • Last update:August 04, 2026
  • Overview

    Application Scenario

    When using a web service as a data source for your project, you may want reports to directly call the web service instead of defining a data connection to use the corresponding database table. This document describes how to implement this.

    Implementation Method

    You can use the Java program to access the web service, convert the data returned by the web service into a class dataset, and then use the dataset in the designer. In this example, the web service data source is published from a JWS file and accessed directly.

    Example

    In an Axis 1.4 project, publish a web service from a JWS file. Then use Java code to send a Simple Object Access Protocol (SOAP) request to the web service and retrieve the data.

    Preparing the Web Service Data Source

    Preparing the Axis Server

    If you have set up an Axis server, skip this step.

    1. Download and install the Java Development Kit (JDK) and a web application server to set up the deployment environment. This example uses Tomcat, which has been set up in advance.

    2. Download the deployment package (axis-bin-1_4.zip in this example) from the Axis official website, extract the package, copy webapps/axis to the Tomcat installation directory/webapps path, and start Tomcat. If you can access the Axis service via a URL in a browser, the deployment is successful. This example uses a local server, so enter http://localhost:8080/axis/ in the browser. If the Apache-AXIS page is displayed, the deployment is successful.

    2.1.1.png

    Publishing a Web Service

    Publish a web service from a JWS file named TestWS2TDClient.jws in the Axis project under Tomcat. The service returns array data.

    1. Create a TestWS2TDClient.java file with the following content:

    public class TestWS2TDClient {
    public String[][] getTD() {
    String[][] a = { { "City", "Salesperson", "Sales" }, { "New York", "Anna", "230" }, { "Los Angeles", "Alex", "190" },
     { "Chicago", "Jack", "320" }, { "Houston", "Kate", "210" }, { "Phoenix", "Faye", "150" }, { "Seattle", "Sammi", "280" } };
    return a;
     }
     }

    2. Rename TestWS2TDClient.java to TestWS2TDClient.jws, set the encoding format to GBK, and place the file under Tomcat installation directory/webapps/axis/. In this way, the sample data is published as a web service, as shown in the following figure.

    2.1.2.png

    3. Access http://localhost:8080/axis/TestWS2TDClient.jws in the browser, as shown in the following figure.

    2.1.2-2.png

    Click Click to see the WSDL. If the Web Services Description Language (WSDL) content is displayed, the service is published successfully, as shown in the following figure.

    iconNote: 
    If an error is reported indicating that tools.jar is required, copy tools.jar from JDK installation directory/lib to Tomcat installation directory/webapps/axis/WEB-INF/lib.

    2.1.2-3.png

    Defining a Class Data Source

    The web service data source has been prepared in the "Preparing the Web Service Data Source" section. Next, use Java to send a SOAP request to access the TestWS2TDClient.jws web service and retrieve the data. Then, define the WebServiceTableData.java class that extends SimpleTableData, and convert the obtained array data into a class dataset.

    Preparing the Compilation Environment

    Before compiling the program, you need to create a Java project environment and prepare a Java editor (for example, Eclipse or IntelliJ IDEA).

    Import the JAR files of your FineReport project into the editor. The JAR files include:

    • All files in FineReport installation directory/lib

    • All files in FineReport installation directory/server/lib

    • All files in FineReport installation directory/webapps/webroot/WEB-INF/lib

    • tools.jar in JDK installation directory/lib

    • JAR files in Axis installation directory/WEB-INF/lib

    For details, see Compiling a Java Program.

    Writing the Java Program

    Use Java to send a SOAP request to access the TestWS2TDClient.jws web service and retrieve the data. The code is as follows:

    iconNote: 
    SOAP stands for Simple Object Access Protocol. A client sends a SOAP request to call the corresponding object, and the server returns the result. SOAP uses XML as its message format and operates over application layer protocols such as HTTP.
    try {
                String endpoint = "http://localhost:8080/axis/TestWS2TDClient.jws";
                Service service = new Service();
                Call call = (Call) service.createCall();
                call.setTargetEndpointAddress(new java.net.URL(endpoint));
                call.setOperationName(new QName("http://localhost:8080/axis/TestWS2TDClient.jws",
                        "getTD"));
                String[][] ret = (String[][])call.invoke(new Object[] {});
                return ret;
            } catch (Exception e) {
                e.printStackTrace();
            }

    After the web service is called, the service returns data to the client. In this example, a string array is returned. Create the WebServiceTableData.java class that extends SimpleTableData, and convert the obtained array data into a class dataset.

    You can click to download the complete code: WebServiceTableData.java.zip

    Compiling the Java File

    After writing the Java program, compile WebServiceTableData.java with the Java compiler. After compilation succeeds, the WebServiceTableData.class file is generated in the output directory of the corresponding project, as shown in the following figure.

    2.2.3-1.png

    Copy the compiled WebServiceTableData.class file to FineReport installation directory/webapps/webroot/WEB-INF/classes/com/fr/data, as shown in the following figure.

    iconNote: 
    During remote design, the class file corresponding to the class dataset must be placed in both the local designer project and the remote server project.

    2.2.3-2.png

    Creating a Class Dataset

    Copy the JAR files in Axis installation directory/WEB-INF/lib to FineReport installation directory/webapps/webroot/WEB-INF/lib of the report project, excluding log4j-1.2.8.jar because it causes a conflict. After the files are copied, restart the report project so that the third-party JAR files can be loaded.

    2. Create a template, click the icon above Template Dataset, select Class to open the Class Dataset window, and select the required class file.

    2.3.png

    After selecting the class file, click OK to complete the class dataset configuration.

    Using the Class Dataset

    After the class dataset is configured, drag data columns to cells to bind the data, as you do with other datasets, as shown in the following figure.

    iconNote: 
    When you use the class dataset, ensure that the Axis server has been started.

    2.4.png

    Attachment List


    Theme: Secondary Development
    Already the First
    Already the Last
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy