Exposing EJBs as web services
In our previous web service example, we saw how we can expose a Plain Old Java
Object (POJO) as a web service by packaging it in a web application and adding a
few annotations to it. This makes it very easy to create web services deployed in a
When working with an EJB module project, we can have stateless session beans
exposed as web services. This way, they can be accessed by clients written in
languages other than Java. Exposing stateless session beans as web services has the
effect of allowing our web services to take advantage of all the features available to
EJBs, such as transaction management and aspect oriented programming.
There are two ways of exposing a session bean as a web service. When creating a
new web service in an EJB module project, the web service will automatically be
implemented as a stateless session bean. Additionally, existing session beans in an
EJB module project can be exposed as a web service.
Implementing new web services as EJBs
In order to implement a new web service as an EJB, we simply need to create the web
service in an EJB Module or Web Application project by right-clicking on the project
and selecting New | Web Service .
When using a web application project to create our SOAP-based web
service, we are given the option of implementing the web service as a
POJO or as a stateless session bean. When using an EJB module project,
we can only implement the web service as a stateless session bean.