Step 1: Begin the Investigate Web Service

In this step, you will use WebLogic Workshop to create a simple, synchronous web service called the Investigate web service. You will also deploy and run Investigate on WebLogic Server.

The tasks in this step are:

To Start WebLogic Workshop

... on Microsoft Windows

If you are using a Windows operating system, follow these instructions.

  1. From the Start menu, choose Programs-->WebLogic Platform 8.1-->QuickStart.
  2. In the QuickStart dialog, click Experience WebLogic Workshop 8.1.

...on Linux

If you are using a Linux operating system, follow these instructions.

  1. Open a file system browser or shell.
  2. Locate the Workshop.sh file at the following address:
    $HOME/bea/weblogic81/workshop/Workshop.sh
    
  3. In the command line, type the following command:
    sh Workshop.sh
    

To Create a New Application

  1. From the File menu, select New --> Application. The New Application dialog appears.
  2. In the New Application dialog, in the upper left-hand pane, select Tutorial.
    In the upper right-hand pane, select Tutorial: Web Service.
    In the Directory field, use the Browse button to select a location to save your source files. (The folder you choose is up to you. The default location is shown in the illustration below.)
    In the Name field, enter WebServiceTutorial.
    In the Server field, from the dropdown list, select BEA_HOME\weblogic81\samples\domains\workshop.

  3. Click Create.

    A new Tutorial: Web Service application is created. Note that this application contains a number of resources that you will use in this tutorial. The most import resource is the Investigate Java control. For details on the structure of and functionality of the Investigate Java control see Tutorial: Java control.

To Start WebLogic Server

Once you have created a new web service tutorial application, you must ensure that WebLogic Server is running while you build your web service.

You can confirm whether WebLogic Server is running by looking at the status bar at the bottom of WebLogic Workshop. If WebLogic Server is running, a green ball is displayed as pictured below.

If WebLogic Server is not running, a red ball is displayed, as pictured below.

If you see the red ball in the status bar, then follow the instruction below to start WebLogic Server.

Note: On the Start up Progress dialog, you may click Hide and continue to the next task.

To Create a New Web Service

In this step you will create a new web service called Investigate.jws. The code for a web service is contained within a JWS file ("JWS" stands for "Java Web Service"). A JWS file is a JAVA file in that it contains code for an ordinary Java class. But, because a file with a JWS extension contains the implementation code intended specifically for a web service class, the extension gives it special meaning in the context of WebLogic Server, where your web service will be deployed.
  1. On the Application tab, right-click the folder WebServiceTutorial/WebServiceTutorialWeb/investigateJWS folder and select New-->Web Service.

  2. In the New File dialog, in the upper left-hand pane, confirm that Web Services is selected.
    In the upper right-hand pane, confirm that Web Service is selected .
    In the File name field, enter Investigate.jws.

  3. Click Create.

    A new JWS file, Investigate.jws, is created and displayed in the main work area in Design View.

To Add a New Method

Web services expose their functionality through methods, methods that clients invoke when they want to request something from the web service. In this case, clients will invoke a method to request credit reports. The service you are building will eventually collect credit information from other sources. But for now, to keep things simple, you will provide a method that returns a simple report immediately.

  1. Confirm that Investigate.jws is displayed in the main work area. (Throughout this tutorial, to display a file in the main work area, double-click its icon on the Application tab.)
  2. Click the Design View tab.
  3. From the Insert menu, select Method.
  4. In the space provided, replace newMethod1 with requestCreditReport and press Enter.

    Note: If you switched from WebLogic Workshop to another application (for example, to read this topic), the method name may no longer be available for editing. To re-open it for editing, right-click its name, select Rename, type requestCreditReport, and then press Enter.

To Specify a Parameter and Return Value

In this task you will complete the requestCreditReport method by adding a parameter and a return value.

  1. In Design View, click the link text for the requestCreditReport method, as shown in the following illustration.



    The web service switches from Design View to Source View, with the cursor placed in front of the requestCreditReport method, as shown below.



    Note: the method has a Javadoc comment (Javadoc comments always begin with /** and end with */). Javadoc was originally introduced as a way to specify inline documentation that could be extracted and presented as HTML. WebLogic Workshop uses a variety of Javadoc annotations to indicate how web service code should be treated by WebLogic Server at runtime. In this case, the Javadoc annotation "@common:operation" indicates that the method should be exposed to clients as accessible over the internet.
  2. Edit the requestCreditReport method body so it appears as follows. Code to edit appears in red.
        /**
         * @common:operation
         */
        public String requestCreditReport(String taxID)
        {
            return "Applicant " + taxID + " is approved.";
        }
    As you can see, this is not a very interesting credit evaluation process. In the next step of the tutorial, you will implement a more precise evaluation process.
  3. Press Ctrl+S to save your work.

As it is now written, the requestCreditReport method works like this: the client invokes the method by supplying a tax identification number, the method then immediately returns a String to the client saying that the applicant with the supplied tax identification number was approved.

Before you go on to test your web service, click the Design View tab.


The long blue arrow indicates that the requestCreditReport method is an operation: a method of your web service that is exposed to clients. (The long blue arrow is the graphical equivalent of the Javadoc annotation @common:operation.)

The white arrow pointing to the right indicates that the requestCreditReport method takes one or more parameters. In this case, the requestCreditReport takes one parameter: the String taxID.

The white arrow pointing to the left indicates that the method returns some data. In this case, the method returns the String value "Applicant " + taxID + " is approved."

To Test the Investigate Web Service

You can test and debug code with the Workshop Test Browser, a browser-based tool through which you can call methods of your web service.

  1. Click the Start button, shown in the following illustration.


  2. Clicking the Start button prompts WebLogic Workshop to build your project, checking for errors along the way. WebLogic Workshop then launches a web browser through which you can test your web service. The following illustration shows the Test Form page that appears after you click the Start button.


    As you can see, this page provides tabs for access to other pages of the Test View. Test Form and Test XML provide alternative ways to specify the content of the call to your service's methods. Overview and Console include additional information and commands useful for debugging a service.
  3. If it is not already selected, click the Test Form tab.
  4. In the string taxID field, enter a value. (This value can be any string value.)
  5. Click requestCreditReport.

  6. The browser refreshes to display a summary of your request parameters and your service's response, as shown here:

    Under Service Request, the summary displays the essence of what was sent by the client (= you) when the method was called. It shows the parameter values passed with the method call, as in the following example:

    taxID = 123456789

    Under Service Response, the summary displays what was returned by the Investigate web service. The response is formatted as a fragment of Extensible Markup Language (XML), this is the payload of the SOAP message returned by the web service.

    To the left of the request and response is the Message Log area. This area lists a separate entry for each test call to the service method. Entries in the Message Log correspond to your service's methods, updating with a new entry for each test you make.

    To try this out, click the Test operations link to return to the original Test Form page, then enter a new value in the string taxID box and click requestCreditReport. When the page refreshes, request and response data corresponding to your second test is displayed as a second entry in the Message Log. You can click each log entry to view the data for the corresponding test. Click Clear Log to empty the list of log entries and start fresh.

  7. Return to WebLogic Workshop, and click the Stop button (shown below) to close the Workshop Test Browser.

 

Related Topics

Applications and Projects

Click one of the following arrows to navigate through the tutorial.