Saturday, 19 October 2013

A simple WebService using JDK


To develop a Soap WS in standalone Java (no web/app server).


  • JDK 1.7
  • Eclipse IDE


  • Create a Eclipse Java Project and add a class definition as given below:
package test;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

@WebService(name = "Alarm", serviceName = "AlarmingService", portName = "AlarmPort")
public class AlarmingListenerImpl {

    public String sendAlarm(@WebParam(name = "alarm") String alarm) {
        if (alarm != null) {
            System.out.println("Message received:" + alarm);
        return "success";

    public static void main(String[] args) {
        // Start Alarm Listener
        Endpoint endPoint = Endpoint.create(new AlarmingListenerImpl());
  • Start the class (main method is written in the same class); this will be running and listening on port 9001 for any WS requests.


  • You need any WS client to test the WS you just created.
  • I used Eclipse Java EE Perspective's "Web Service Explorer" (Run -> Launch the Web Service Exporer):
  • You can also try JDK provided tool wsimport to generate WS Client classes and write a Java client.
Thanks You!