In order to expose a stateless session bean as a Web service, the stateless session bean must first be created in an EJB project. Naturally, an existing stateless session bean coded according to EJB 3.0 specifications can also be exposed as a Web service.
Then, the Web service can be exposed by declaring the @WebService annotation in the stateless session bean.
Creating the Stateless Session Bean
Create the stateless session bean in an EJB project.
For details on the creation method, refer to "3.3.1 Preparing the Environment to create EJBs" and "3.3.2 Creating Session Beans".
Declaring the WebService Annotation
Code the @WebService annotation in the stateless session bean as shown below.
Example of using the WebService Annotation
package sample; import javax.jws.WebService; import javax.ejb.Stateless; @WebService @Stateless public class Calc { public int add(int param1,int param2) { return param1 + param2; } } |