Show TOC

Exposing the Enterprise Java Bean as a Web ServiceLocate this document in the navigation structure

Context

You expose the implementation bean as a Web service by using the WebServices wizard that is integrated in the SAP NetWeaver Developer Studio. When you expose the implementation bean, you can use service endpoint interface (SEI) to expose some or all methods of the implementation bean as Web service methods. More information: Service Endpoint Interface .

In this tutorial, you use the remote interface of the Enterprise Java Bean as an SEI

Procedure


  1. In the Project Explorer, expand the HelloWorldEJB project, and then choose Start of the navigation path ejbModule Next navigation step com.sap.tutorial.helloworld  Next navigation step  HelloBean.java End of the navigation path.

  2. Right-click HelloBean.java , and then choose Start of the navigation path Web Services Next navigation step Create Web Service End 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, as shown in the figure below.

  6. Choose Browse and then in the Select Service endpoint interface , enter com.sap.tutorial.helloworld.HelloRemote .

  7. From the Matchingitems area, choose the HelloRemote interface. When the HelloRemote interface 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 .

    The Method Selection screen opens.

  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 Enterprise Java Bean is exposed as a Web service.

The framework generates the relevant standard Web service annotations in the implementation bean and in the SEI.

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="HelloRemote", targetNamespace="http://sap.com/tutorial/helloworld/")
@Remote
public interface HelloRemote {
        @WebMethod(operationName="sayHello")
        public String sayHello (@WebParam(name="name")
        String name);
}

         

The code sample below shows the update of the implementation bean:

package com.sap.tutorial.helloworld;
import javax.ejb.Stateless;
import javax.jws.WebService;

@WebService(endpointInterface="com.sap.tutorial.helloworld.HelloBean_nckRemote", portName="HelloBean_nckBeanPort", targetNamespace="http://sap.com/tutorial/helloworld/", serviceName="HelloBean_nckService")
@Stateless(name="HelloBean")

public class HelloBean implements HelloBean, HelloBean {
   private String message = "Hello, ";
   public String sayHello(String name) {
   return message + name + ".";
   }
}