Show TOC Start of Content Area

Procedure documentation Exposing the Enterprise Java Bean as a Web Service  Locate the document in its SAP Library structure

Use

You expose the implementation bean as a Web service by using the Web Services 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 ejbModule com.sap.tutorial.helloworld HelloBean.java.

       2.      Right-click HelloBean.java, and then choose Web Services Create Web Service.

The Web Services wizard appears.

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

This graphic is explained in the accompanying text

       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 Matching items area, choose the HelloRemote interface. When the HelloRemote interface is selected, the Web service annotations are generated in the remote Java interface.

This graphic is explained in the accompanying text

       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.

This graphic is explained in the accompanying text

   11.      Choose Finish.

Result

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:

Syntax

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:

Syntax

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 + ".";

   }

}

Next Step

Deploying the HelloWorld Web Service

 

 

 

End of Content Area