Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.1.0) Part Number B28221-02 |
|
|
View PDF |
The client of a stateless session bean may be a Web service client. Only a stateless session bean may provide a Web service client view. A Web service client makes use of the enterprise bean's Web service client view, as described by a WSDL document. The bean's client view Web service endpoint interface is a JAX-RPC interface.
Using EJB 3.0, you can use annotations to easily expose a stateless session bean as a Web service (see "Using Annotations").
Using EJB 2.1, you can also expose a stateless session bean as a Web service (see "Assembling a Web Service with EJBs" in the Oracle Application Server Web Services Developer's Guide).
Using the @WebService
and @WebMethod
annotations, you can define a Web service endpoint interface, as Example 30-1 shows, and implement the Web service as a stateless session bean, as Example 30-2 shows.
Example 30-1 Annotated Web Service Endpoint Interface
package oracle.ejb30.ws; import javax.ejb.Remote; import javax.jws.WebService; import javax.jws.WebMethod; @WebService /** * This is an Enterprise Java Bean Service Endpoint Interface */ public interface HelloServiceInf extends java.rmi.Remote { /** * @param phrase java.lang.String * @return java.lang.String * @throws String The exception description. */ @WebMethod java.lang.String sayHello(java.lang.String name) throws java.rmi.RemoteException; }
Example 30-2 Implementing the Web Service as a Stateless Session Bean
package oracle.ejb30.ws; import java.rmi.RemoteException; import java.util.Properties; import javax.ejb.Stateless; /** * This is a session bean class */ @Stateless(name="HelloServiceEJB") public class HelloServiceBean implements HelloServiceInf { public String sayHello(String name) { return("Hello "+name +" from first EJB3.0 Web Service"); } }
OC4J supports J2SE 5.0 Web Service annotations (also known as the Web Services Metadata for the Java Platform JSR-181) specification. The specification defines an annotated Java syntax for programming Web services.
For more information on using Web service annotations including Oracle extensions, see "Assembling Web Services with Annotations" in the Oracle Application Server Web Services Developer's Guide.
For other EJB Web service examples see the stateless session EJB Web service how-to or Adventure Builder how-to at http://www.oracle.com/technology/tech/java/ejb30.html
.