BLOG

How I Built My Own SAP NetWeaver Web Service in 30 Minutes

Header-Design Augmentation
architectsap-web-services

Do you think that creating a web service in SAP NetWeaver takes a lot of coding and it is time consuming ? Here I am going to explain you how it can be done in a matter of minutes and in simple and easy steps.

Let us understand following steps for creating “HelloEmployee” web service.

1. Creating an EJB :

1. In the SAP NetWeaver Developer Studio, choose the Java EE perspective and create an EJB project and an Enterprise Application Project.

2. Name the Project as HelloEmployee and choose Add Project to an EAR and name EAR project as HelloEmployeeEAR.

3. In the EJB project wizard choose next twice, deselect the EJB Client Jar. And choose finish.

After completion the of above steps, You can see the HelloEmployee and HelloEmployeeEJB Project in the Project Explorer.

2. Creating the Enterprise Java Bean :

1.  In the Project explorer explore HelloEmployee project ejbModule create a package as ‘com.sap.practice.

2.  In the same package choose New Session Bean (EJB) name it as HelloBean

3. In the Create business interface area, select both Remote and Local and choose finish.

4.  Update the source code as follows

5. In the Project Explorer, expand the HelloEmployeeEJB project, and then choose ejbModule → com.sap.practice.helloEmployee → HelloBean.java → HelloBean → sayWelcome(String).

6. Right-click sayWelcome(String), and then choose EJB Methods → Add to Local and Remote Interfaces.

7. Save your changes. Result of above steps : The HelloBean appears in the ‘HelloEmployeeEJB’ project. The ‘sayWelcome’ class is added to the local and remote Java interfaces. At this point, the implementation session bean is ready to be exposed as a Web service.

3. Exposing the Enterprise Java Bean as a Web Service :

You can expose the implemented Bean as web service by using SAP wizard in SAP NWDS. Steps :

1. In the Project Explorer, expand the HelloEmployeeEJB project, and then choose ejbModule → HelloBean.java.

2. Right-click HelloEmployee.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.

4.  Click next, choose “specify existing interface” browse and select com.sap.practice. HelloBeanRemote interface.

5. WSDL URL Preview is the URL which we will be using in our WebDynpro Model. 6. Select method ‘SayWelcome’ which will be exposed in the web service. 7. Choose finish.

Result : The Enterprise Java Bean is exposed as a Web service.

4. Deploying the HelloWorld Web Service :

  1. Make sure that SAP NWDS is connected to application server and server is running.
  2. Choose Window → Show View → Servers.
  3. On the Servers tab page, right-click SAP Server, and then choose Add and Remove Projects.
  4. From the list of available projects, choose HelloEmployeeEJBEAR, and then choose Add.
  5. Choose Finish.
  6. If prompted, log on to the application server as Administrator.

Result : The Web service endpoint is on the application server.

Hope you understood  how to build a simple web service in SAP NetWeaver.

Need Help:

In case you need assistance on SAP NetWeaver Web Services, please contact us.  Please send us your questions, comments or assistance request and our team would be glad to assist you.

By  Yashpal Mote (on behalf of SAP Consulting Team)


Apprisia
SAP :: Streamlined

We offer variety of services including SAP ECC ,SAP HR,SAP BW,SAP CRM, SAP SCM,SAP BPM, Business Objects, SAP ABAP DevelopmentSAP BASIS and SAP NetWeaver consulting. We have expertise in providing implementation,development, SAP Migration and SAP support services to SAP customers across diverse industries at a global level.

Have a question on SAP? Write to our SAP Architect : AskTheArchitect@Apprisia.com

(We promise a no-obligation consulting reply)