Vous êtes sur la page 1sur 12

GUIDE TO CREATE A WEB SERVICE FROM A JAVA CLASS

GUIDE TO CREATE A WEB SERVICE FROM A JAVA CLASS

Applies to:
SAP NetWeaver Developer Studio 7.0.11

Summary
Using this document anyone can easily create a Web Service from a java class in SAP NetWeaver; just you
have to fellow these steps.
Author: Rajes Ghosh
Company: HCL Technologies Ltd
Created on: 6 June 2007

Author Bio

Rajes Ghosh is working as a SAP NetWeaver Consultant for HCL Technologies Ltd.

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


1

GUIDE TO CREATE A WEB SERVICE FROM A JAVA CLASS

Table of Contents
Applies to: ........................................................................................................................................ 1
Summary.......................................................................................................................................... 1
Author Bio ........................................................................................................................................ 1
STEPS TO FELLOW ....................................................................................................................... 3
1. CREATE A JAVA PROJECT ....................................................................................................... 3
2. CREATE PACKAGE & JAVA CLASS ......................................................................................... 3
3. CONSTRUCT REQUIRED METHOD ......................................................................................... 4
4. OPEN WEB SERVICE PERPECTIVE......................................................................................... 4
5. CREATE WEB SERVICE ............................................................................................................ 5
6. PROVIDE WEB SERVICE NAME, CONFIGURATION TYPE & CONFIGURATION NAME...... 5
7. SELECT THE REQUIRED METHOD TO EXPOSE AS WEB SERVICE.................................... 6
8. PROVIDE VIRTUAL INTERFACE & WEB SERVICE DEFINATION NAME............................... 6
9. BUILD EAR FILE ......................................................................................................................... 7
10. DEPLOY THE EAR FILE ........................................................................................................... 7
11. DEPLOYMENT FINISHED ........................................................................................................ 7
12. OPEN WEB SERVICE NEVIGATOR TAB & REFRESH .......................................................... 8
13. OPEN THE WEB SERVICE ...................................................................................................... 8
14. TEST THE WEB SERVICE ....................................................................................................... 9
15. TEST INPUT SCREEN............................................................................................................ 10
16. OUTPUT SCREEN .................................................................................................................. 10
17. REQUEST SOAP XML MESSAGE ......................................................................................... 11
18. RESPONSE SOAP XML MESSAGE ...................................................................................... 11
Related Content............................................................................................................................. 11
Disclaimer and Liability Notice....................................................................................................... 12

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


2

GUIDE TO CREATE A WEB SERVICE FROM A JAVA CLASS

STEPS TO FELLOW

1. CREATE A JAVA PROJECT


Here we are creating the java project in SAP NetWeaver Developer Studio to create a java class. In that java
class we will write down a method to expose that as web service.

2. CREATE PACKAGE & JAVA CLASS


Here we are declaring the a package to create the java class and also creating the java class as
MyEMIClaculator.

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


3

GUIDE TO CREATE A WEB SERVICE FROM A JAVA CLASS

3. CONSTRUCT REQUIRED METHOD

Here EMICalculation is the required method in class MyEMICalculator, which we are going to expose as
Web Service.

4. OPEN WEB SERVICE PERPECTIVE


Open the Web Service Perspective by Clicking the Web Service
Perspective Icon pointed out in the picture.

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


4

GUIDE TO CREATE A WEB SERVICE FROM A JAVA CLASS

5. CREATE WEB SERVICE


This is the Web Service Perspective.
Click on the New Web Service
Menu to get the Web service creation
widget.

6. PROVIDE WEB SERVICE NAME, CONFIGURATION TYPE & CONFIGURATION


NAME

This is the Web Service Creation Widget.


Enter the Web Service name, Configuration type &
Configuration name.
Click Next button.
In configuration type, you will get 3 options. Here
we are taking simple soap for simplicity.

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


5

GUIDE TO CREATE A WEB SERVICE FROM A JAVA CLASS

7. SELECT THE REQUIRED METHOD TO EXPOSE AS WEB SERVICE

Select the method to expose as a Web service. Here


we are selecting one method. If java class has more
method and if required then you can select more
than one method,
Click Next button.

8. PROVIDE VIRTUAL INTERFACE & WEB SERVICE DEFINATION NAME

Here we are entering the Virtual Interface and Web


service definition name.
You can just click to Finish button with the default
values.
It is advisable that keep the default name.

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


6

GUIDE TO CREATE A WEB SERVICE FROM A JAVA CLASS

9. BUILD EAR FILE


In Java Explorer, you can see that virtual interface, web service definition & web service configuration has
been created.

Click on the Build EAR menu by right click to create the EAR file.

10. DEPLOY THE EAR FILE

Select the EAR file and right click on it. You will get
Deploy menu.
Click on the Deploy menu to deploy it in J2EE Engine.

11. DEPLOYMENT FINISHED


You will get a message in Deploy Output
View that deployed finished message. If
there is any error then you will get that
information also.

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


7

GUIDE TO CREATE A WEB SERVICE FROM A JAVA CLASS

12. OPEN WEB SERVICE NEVIGATOR TAB & REFRESH

After deployment if we Refresh the Local Server


then you will find that new Web Service will be
added into the list.

13. OPEN THE WEB SERVICE

WS_MyEMICalculator is the new Web Service


added in the list as in pointed out in picture.
Open this Web Service.

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


8

GUIDE TO CREATE A WEB SERVICE FROM A JAVA CLASS

14. TEST THE WEB SERVICE

Click on Test link to test the web service.


Test Screen

Click on the Method Name EMICalculation to test it.

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


9

GUIDE TO CREATE A WEB SERVICE FROM A JAVA CLASS

15. TEST INPUT SCREEN

Give the input and Click on the Send button to get the test the web service.

16. OUTPUT SCREEN


This is request/response screen. In request we have send some value as input to the web service. Response
is coming from the web service after execution the method. So we are getting the result.

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


10

GUIDE TO CREATE A WEB SERVICE FROM A JAVA CLASS

17. REQUEST SOAP XML MESSAGE


Request is gone to the web service as a XML. Here we are showing the request XML message.

18. RESPONSE SOAP XML MESSAGE


Response is come from web service also as a xml message. So here is the response xml message.

Related Content
Please refer to this web page if you want to know more.
http://help.sap.com/saphelp_nw04/helpdata/en/30/581e3e6217b40be10000000a114084/frameset.htm

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


11

GUIDE TO CREATE A WEB SERVICE FROM A JAVA CLASS

Disclaimer and Liability Notice


This document may discuss sample coding or other information that does not include SAP official interfaces
and therefore is not supported by SAP. Changes made based on this information are not supported and can
be overwritten during an upgrade.
SAP will not be held liable for any damages caused by using or misusing the information, code or methods
suggested in this document, and anyone using these methods does so at his/her own risk.
SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of
this technical article or code sample, including any liability resulting from incompatibility between the content
within this document and the materials and services offered by SAP. You agree that you will not hold, or
seek to hold, SAP responsible or liable with respect to the content of this document.

SAP DEVELOPER NETWORK | sdn.sap.com


2007 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com


12

Vous aimerez peut-être aussi