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

Step 3: Add a Web Method to the Web Service

In this section, you'll create a simple web method (a method that can be invoked over the web) in the web service. This operation is designed to return customer data. In a real world application, this method would probably perform some database lookups. In this simple example, your service will simply return the name "John Smith" to all customer enquiries.

Before you start, be sure that Workshop for WebLogic has open for editing in the Design View. To ensure that the file is open for editing, double-click on in the Package Explorer view.

  1. In Design View, right-click the hello method icon (either the arrows or the link text will work) and select Edit Signature.

    Edit signature

  2. In the editing area that appears, change the text from void hello() to String getCustomers() and press Enter.

    Signature edited

    At this point, the method will be marked with red-underlining, indicating a compile error. In the next step, you will correct that error.

  3. In Design View, right-click the hello method icon and select Edit Source.
  4. Edit source

  5. In the method body enter the following return statement:
    return "John Smith"; 

    The final method should appears as follows:

        public String getCustomers() {
            return "John Smith";
  6. Save the file with the File > Save command or by pressing Ctrl+S.

In Source View, the class should now look like this:

package services;
import javax.jws.*;
public class MailingListService {

   public String getCustomers() {
       return "John Smith";

In Design View, the class should look like this:

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


Skip navigation bar   Back to Top