05 - Web Service example in Java: Page 2 of 3

Now that we have our web service demo project in place, let’s start creating our initial class. Right click on the source folder and create a new class, called WSDemo and click Finish.


In the WSDemo class, let’s define a new method that receives a String as parameter and returns a message:

package com.demo.goj;
publicclass WSDemo {
       public String helloWorld (String name)
              return"Greetings " + name + "! You have reached the web service!";

Once we access our web service we will see how this message is returned later in this tutorial.

Now, let’s use eclipse built in plugin for creating web services.

Right click on the WebServiceDemo project and select New / Other



Once the new window is opened, select Web Services / Web service and click Next



You should see the Web Service screen. Here le’ts select the class we created so it is exposed as a web service, in our case the WSDemo.java class, so let’s reference it by the fully qualified class name: com.demo.goj.WSDemo.



On the configuration part of the screen, click on the Web Service Runtime: and select Axis2 and click OK


Like us on Facebook