Step 3: Integrate XMLBeans into a Web Service

Here, you'll create a web service to test with.

The tasks in this step are:

To Create a Web Service

  1. In the Project Explorer, expand XMLBeansWebService > Java Resources, right-click the src folder and select New > Package.
  2. In the New Java Package dialog, in the Name field, enter purchasing.services and click Finish.
  3. Right-click the purchasing.services package, then click New > WebLogic Web Service.
  4. In the New Web Service dialog, in the File name field, enter ItemService, then click Finish.

To Invoke XMLBeans Classes

  1. When the ItemService design is displayed, click hello to edit the method's code.
  2. In Source View, add the following import statement to import the types generated from your schema:
    import org.example.purchaseItem.*;
  3. Replace the @WebMethod annotation and hello method code with the following:
        @WebMethod 
        public double calculateTotal(ItemDocument itemDoc) {
            ItemType item = itemDoc.getItem();
            double itemPrice = item.getPrice();
            int itemQuantity = item.getQuantity();
            return itemPrice * itemQuantity;
        }
  4. Save your changes.

To Run the Web Service

  1. In the Project Explorer, right-click the node ItemService.java and select Run As > Run on Server.
  2. In the Run On Server dialog, click Finish.

    Wait for the web service to deploy to the server.
    A web browser tab will appear showing the WebLogic Test Client, a testing environment you can use to exercise the methods of your web service.
  3. In the Test Client, under the calculateTotal operation name, you'll see a box containing XML based on the schema you created. This is intended to be a template for testing.
  4. In the template XML, you can replace values in the <price> and <quantity> elements with values you want to test with.
  5. Click calculateTotal to test the web service.

    The Test Client will refresh to display XML representations of the request and response messages received and sent by your web service.

    Note that the response includes the sum calculated from values retrieved from XML via generated types.

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


Still need help? Post a question on the Workshop newsgroup.