Step 4: Add a Service Control

Below we will add a service control to your web service. In other words, you will add a CTRL file which allows your web service to invoke another external web service. This other web service provides credit card data on a credit applicant.

The tasks in this step are:

- To generate a CTRL file from a WSDL file

- To add the CTRL file to your web service

- To add code to invoke an external web service

- To add code to handle callbacks from the external web service

- To test the web service

To Generate a CTRL File from a WSDL File

By definition, each web service provides a WSDL file that explains how the web service is operated. In this task you will automatically generate a CTRL file based the WSDL file of another web service. The resulting CTRL file is incorporated into your web service to form the interface between your web service and the external web service.

1. In the Project tree, expand the tutorials folder, then expand the tutorial_support folder, finally expand CreditCardReport.jws as shown below.

2. Right-click the CreditCardReportContract.wsdl file and select Generate CTRL from WSDL, as shown here:

Note that a new CTRL file is generated and placed underneath CreditCardReportContract.wsdl.

To Add the CTRL File to Your Web Service

In this task you will add the new CTRL file to your web service. With the CTRL file added you will be able to invoke the external web service that provides credit card data.

1. If you are not in Design View, click the Design View tab.

2. Drag and drop the newly generated CreditCardReportContract.ctrl from the Project Tree into Design View. A new service control, like the one shown below, is added to your web service.

To Add Code to Invoke the External Web Service

In this task you will add code that invokes the external web service.

1. Click the Source View tab.

2. Edit the requestCreditReportAsynch method to look like the code shown here. Make sure that you delete the line of code shown crossed out below.

        public void requestCreditReportAsynch(String taxID)
            throws java.sql.SQLException
        {
            /*
             * Query the database via the database control
             */
            Applicant dbApplicant = bankruptciesDB.checkForBankruptcies(taxID);
            /*
             * If the database contains data on the current applicant,
             * assign the retrieve values to m_currentApplicant.
             */
            if(dbApplicant != null)
            {
                m_currentApplicant = dbApplicant;
                creditCardReportControl.getCreditCardData(taxID);
            }
            callback.onCreditReportDone(m_currentApplicant, null);
        }

To Add Code to Handle Callbacks from the External Web Service

In this task you will add code to handle the credit card information sent back from the external web service. This code does two things: first, it stores the relevant credit card data in the member variable m_currentApplicant. Second, it sends the applicant profile back to the client using the callback onCreditReportDone.

1. If you are not in Design View, click the Design View tab.

2. Click creditCardDataResult.

3. Edit the callback handler to look like the following:

        private void creditCardReportControl_creditCardDataResult(CreditCard[] cards)
        {
            for(int i = 0; i < cards.length; i++)
            {
                m_currentApplicant.availableCCCredit += cards[i].availableCredit;
            }
            callback.onCreditReportDone(m_currentApplicant, null);
        }

4. Press Ctrl+S to save the file.

To Test the Web Service

You are now ready to test the new features of your web service.

1. Click the Start button, shown here:

WebLogic Workshop tests and compiles the web service. A browser is launched displaying Test View.

2. When Test View launches, type one of the following nine-digit numbers in the taxID box for requestCreditReportAsynch, as shown below:
   123456789, 111111111, 222222222, 333333333, 444444444, 555555555

3. Click requestCreditReportAsynch. The Test View page refreshes to display a summary of the request parameters sent by the client and your service's response, as shown here:

4. In the Message Log click the Refresh button. New entries appear in the Message Log, as shown here:

5. Click callback.onCreditReportDone. The callback sent from the web service to the client appears.

Related Topics

Service Control: Using Another Web Service
Click one of the following arrows to navigate through the tutorial.

####