Skip to Content
Author's profile photo Monalisa Biswal

Develop Webservice from WSDL

This document describes how to develop a webservice fast using a WSDL.

In the WSDL, you will provide input/output parameters for the webservice. With the webservice framework you can generate the EJB class from WSDL to incorporate the business logic.

Let’s take one sample scenario to build the webservice.

Webservice will take employees’ locations in the input and calculate total number of employees residing in each city/state.

Step 1: Define your Webservice Structure.

Input

—->ReportCat(City/State)

—->Employee(Cardinality 1..n)

—————->EmployeeId

—————->Name

—————->City

—————->State

—————->Country

Output

—->EmployeeCount(Cardinality 1..n)

—————->Location(City/State)

—————->No_of_Employees

Step 2: Create one EJB DC.

WS1.png

Click on Finish to create the EJB DC.

Step 3: Create one EAR DC to deploy EJB DC.

WS2.png

Go to component properties for the ear dc, provide deployment dependency for the ejb dc.

WS3.png

WS4.png

Step 4: Now create WSDL in your EJB DC. Right Click on the root folder for EJB DC, click on New->Other->Web services->WSDL.

WS5.png

Give a name to your WSDL, choose SOAP Binding as RPC literal and click on finish.

WS6.png

WS7.png

Open WSDL to define structure for the webservice.

WS8.png

Rename Operation name to getEmployeeList and hit enter.

WS9.png

Now add Input/output parameters to the webservice.

Input

—->ReportCat(City/State)

—->Employee(Cardinality 1..n)

—————->EmployeeId

—————->Name

—————->City

—————->State

—————->Country

Right Click on type column for getEmployeeListRequest and change its type to complex(set Type->New Type->Complex Type).

WS10.png

Click on EmployeeInput to open in Design View. Right Click->Click on Add element to add fields to the EmployeeInput type.

The structure should look as below:

WS11.png

Similarly create output structure.

Output

—->EmployeeCount(Cardinality 1..n)

—————->Location(City/State)

—————->No_of_Employees

WS12.png

Your final WSDL should look as below:

WS13.png

Step 5:

Right click on WSDL file->Webservices->Generate JAVA bean Skeleton

WS14.png

Click on Finish. You will find list of JAVA files created as below.

For each type you have defined in the WSDL, it will generate a JAVA class.

It will have one bean class and interface, which would be useful for writing the businesslogic.

WS15.png

So for the above JAVA files: WSEmployee is the interface file and WSEmployeeImplBean is the bean class.

Step 6: Go to the interface file and comment the Webservice declarations as below.

WS16.png

Copy Webservice annotations from this file and paste it in bean file as below.

WS17.png

Step 7: Now edit getEmployeeList method to add calculation logic for number of employees.

This is a sample code assuming the list is already sorted.

public  org.example.wsemployee.EmployeeOutput getEmployeeList(org.example.wsemployee.EmployeeInput getEmployeeListRequest) {

      EmployeeOutput employeeOutput=new EmployeeOutput();

      ArrayList<EmployeeSummary> employeeSum = new ArrayList<EmployeeSummary>();

      EmployeeSummary empSumobj = new EmployeeSummary();

      int count=0,index=0;

      if(getEmployeeListRequest.employeeData!=null)

      {     int employeeSize= getEmployeeListRequest.employeeData.size();

     

            //Check Report category S-For State C-For City

            if(getEmployeeListRequest.reportCat.equals(“S”))

            {

            for(EmployeeDetails employeeDet:getEmployeeListRequest.employeeData)

            {

                  index++;

                 

                  if(employeeDet.state.equals(empSumobj.location)||empSumobj.location==null)

                  {

                        count = count + 1;

                       

                        empSumobj.location=employeeDet.state;

                  }

                  else if(!employeeDet.state.equals(empSumobj.location))

                  {

                       

                       

                       

                        empSumobj.noOfEmployees = count;

                        employeeSum.add(empSumobj);

                        empSumobj=new EmployeeSummary();

                        empSumobj.location=employeeDet.state;

                        count = 1;

                       

                  }

                  if(index==employeeSize)

                  {

                        empSumobj.noOfEmployees = count;

                        employeeSum.add(empSumobj);

                  }

                  }

            }

            }

      employeeOutput.employeeSummary=employeeSum;

       return employeeOutput;

       }

}

Step 8: Deploy the Ear file.

WS18.png

You can find your webservice in WSNavigator(http://host:port/webdynpro/dispatcher/sap.com/tc~esi~esp~wsnav~ui/WSNavigator).

Click on Next to test Webservice.

WS19.png

Click on Next to put test parameters.

WS20.png

Click on Next to execute Webservice. You can find the output in Results column.

WS21.png

WS22.png

You can find more information on help.sap.com at following location:

http://help.sap.com/saphelp_nwce711/helpdata/en/46/9357326110581de10000000a1553f7/frameset.htm

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.