Exposing the EJB as a Web Service

Context

To expose the implementation bean, you can use service endpoint interface (SEI). More information: Service Endpoint Interface .

In this tutorial, you use the remote interface of the EJB as an SEI.

Procedure

  1. In the Project Explorer , expand the HelloWorldEJB project, and then choose Start of the navigation pathejbModule Next navigation step com.sap.tutorial.helloworld Next navigation step HelloBean.javaEnd of the navigation path.
  2. Right-click HelloBean.java , and then choose Start of the navigation pathWeb Services Next navigation step Create Web ServiceEnd of the navigation path.

    The Web Services wizard appears.

  3. Move the slider to Develop service position, as shown in the figure below.
  4. Choose Next .

    The Service Endpoint Interface screen opens.

  5. Choose Specify existing interface option.
  6. Choose Browse and then enter com.sap.tutorial.helloworld.HelloBeanRemote .
  7. From the Matching items area, choose the HelloBeanRemote interface and then OK .

    When the same is selected, the Web service annotations are generated in the remote Java interface.

  8. Choose Next .
  9. In the Web Service Customizations step, choose Next .
  10. On the Method Selection screen, the system displays all explicitly specified methods. Make sure that the sayHello method is selected.
  11. Choose Finish .

Results

The HelloWorld EJB is exposed as a Web service.

The code sample below shows the update of the SEI:


package com.sap.tutorial.helloworld;
import javax.ejb.Remote;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;

@WebService(name="HelloBeanRemote", targetNamespace="http://sap.com/tutorial/helloworld/")
@Remote
public interface HelloBeanRemote {

   @WebMethod(operationName="sayHello")
public String sayHello (@WebParam(name="name") String name);

}