Previous Next vertical dots separating previous/next from contents/index/pdf

Advanced Web Services Tutorial: Step 3: Create a Service Control to Access the CreditScore Web Service

In this step, you will enhance the logic of the LoanApproval control to access the CreditScore web service. The existing logic of the LoanApproval control is:

If a loan exists for this SSN then turn down the application (return false to caller) otherwise accept the application (return true to the caller).

We are going to expand that logic to:

If the person with this ssn already has a loan then turn down their application (return false) otherwise check the credit score. If the credit score is < 700, turn down the application (return false). If the credit score is 700 or higher, accept the application (return true).

To access the external web service, we will create a new web service control ("service control") to access the CreditScore web service. We will then modify the LoanApproval control to use the new web service control.

To Create a Control to Access a Web Service

To create a new control we will first generate a WSDL file from a web service and then generate a service control from the WSDL.

  1. On the Package Explorer view, open the nodes CreditScoreWS > src > services, right-click the web service, and select Web Services > Generate WSDL.

    We will use this WSDL to automatically generate our new control.
  2. To copy the WSDL file, right-click on the file CreditScoreWS/src/services/CreditScoreService.wsdl and select Copy.
  3. Right-click on the LoanApp/src/controls package and select Paste.
  4. Generate a web service control by right-clicking on LoanApp/src/controls/CreditScoreService.wsdl and selecting Web Services > Generate Service Control.

    Confirm that the name for the service control is Click Finish.

  5. In the Package Explorer view, double click the file to open it in the editor.

    Right click on the editor window and choose Insert > Control. Choose the new CreditScoreServiceControl and click OK.

    Code will appear that declares and instantiates the control

    private CreditScoreServiceControl creditScoreServiceControl;
  6. Now replace the current code for getLoanApproval method of the LoanApproval control to expand its logic and use the new web service control.
    public boolean getLoanApproval(int ssn, float amount) throws SQLException
            // if they are already borrowing, don't allow another loan
            if (loansDB.getLoanValue(ssn) > 0)
                return false;
            if(creditScoreServiceControl.getCreditScore(ssn) < 700)
                return false;
            // otherwise, allow the loan.
            loansDB.insertLoan(ssn, amount);
            return true;

    Save your changes with File > Save.

  7. Test the updated web service by right-clicking on in the services package of the LoanApp project and choosing Run As > Run on Server.

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


Skip navigation bar   Back to Top