Java Reference
In-Depth Information
Creating a Basic Web Service
Problem
You want to create a basic but real-world web service in Java EE 5.
Solution
Create an EJB or servlet and annotate it with @WebService . Then package it as you normally
would and deploy it; JAX-WS will take care of creating the WSDL and the necessary map-
pings at deploy time.
Here is the simplest possible way to do it with an EJB:
package com.soacookbook.catalog.ejb;
import com.soacookbook.ns.catalog.*;
import javax.ejb.*;
import javax.jws.*;
/**
* Basic Web Service does shopping cart operations.
*/
@WebService
@Stateless
@Local
public class CartEJB {
public Double getVersion() {
return 5.0;
}
}
This is enough to create a web service that accepts the default mappings. It is important to ex-
amine for a moment what those mappings are. In later recipes, you'll customize the mappings
for the generated WSDL so that the names of your elements are more user friendly.
Note that the bean does not implement a business interface. This may be something that you'd
want to do in the real world, as it makes your bean available to other enterprise processes such
as web-based context listeners, but as of EJB 3, it is no longer strictly necessary.
See Creating and Deploying the Simplest Web Service for how to create and invoke the
simplest possible web service in Java.
Search WWH ::




Custom Search