Web Services - SPLessons

Web Services Calculator Example

Home > Lesson > Chapter 16
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Web Services Calculator Example

Web Services Calculator Example

shape Description

As of now SPlessons explained what is the functionality of web services and what are the modules are there such as SOAP and RESTful. Where SOAP is a protocol and RESTful is architectural style and RESTful is very fast compared to SOAP. The functionality of web services is providing communication between two applications which may be developed with native languages, the following is an example which shows how two JAVA applications will communicate to each via the server.

Calculator Example

shape Description

Generally user can develop an application in two ways with web services such as bottom up and top-down approach, but here SPlessons is going to explain with bottom-up approach. The following are the steps need to be performed.

shape Step - 1

This application is going to develop with the JAVA language so user need to have the following requirements.

shape Step - 2

Here this project is going to be developed based on the calculator. The functionality of calculator is to perform addition, subtraction, division, multiplication etc. The following is the code for the calculator. Calculator.java [java]package com.webServices; public class Calculator { public int add(int a, int b) { return (a + b); } public int subtract(int a, int b) { return (a - b); } public int multiply(int a, int b) { return (a * b); } public int divide(int a, int b) { return (a / b); } }[/java]

shape Step - 3

The original structure of an application will be as follows.

shape Step - 4

Now user need to provide the web service for the Calculator.java program, first click on Calculator.java -> New -> Other -> Web Service -> Next.

shape Step - 5

After doing the above step the following box will be opened. Where select the Bottom up Java bean Web Service and check the Publish the Web service and Monitor the Web service and click on Finish.

shape Step - 6

When click on finish button server will be started and following page will be opened.

shape Step - 7

Now client will be created with some java files and structure will be as follows.

shape Step - 8

When user open the Calculator.wsdl page follwing structure of the data will be displayed on the server as follows.

shape Step - 9

Now perform any operation such as division by giving two values as follows.

Summary

shape Key Points

  • The Axis 2 plug in should be added to the web service project.
  • The WSDL filw will be generated automatically.
  • The WSDL is the part of the UDDI.