[Lab] Creating a Soap Web Service Bottoms Up Using Java SE Endpoint Publisher

In this example we will use bottom up approach to develop a simple SOAP based web service and then publish it using a Java SE Endpoint publisher.

We will not be using any server like Glassfish in this example. Note that all the examples can be executed using an application server like Glassfish or a web container like Tomcat or using only core Java as in this example. I wanted to show the different possibilities.

We will create an interface called Service Endpoint Interface (SEI) and an implementation class called Service Implementation Bean (SIB) that implements this interface. This was how web services were created traditionally. However, current standard allows us to create web services using just a POJO with annotations without a separate interface (as we have seen in the Glassfish example). 


Problem statement

In this example, we will write a simple example web service for getting the time from server.



  1. Create the Service Endpoint Interface (SEI)

  2. Create the Service Implementation Bean (SIB) ​

  3. Create a Publisher class using Endpoint publisher

  4. Compile the classes and run the publisher

  5. Create a client to test the web service using the generated wsdl and run the client

    1. In client, first you need create an URL object for the wsdl url.

    2. Then you need to create a QName object (qualified name of the service) using QName constructor

      1. 1st argument is the service url, which is the value of targetNamespace attribute of the definitions element in WSDL and

      2. 2nd argument is the service name published, which is the value of ‘name’ attribute of the definitions element in the WSDL.

    3. The Service.create() method returns a Service instance.

    4. Calling getPort() on the Service instance (service.getPort()) extract the endpoint interface, the service port, from the service.

    5. The returned port object type is the SEI type and hence you can invoke the portType operations on it.


Step 1: Service Endpoint Interface (SEI)


package com.javajee.ws.tsexample1;

import javax.jws.WebService;

import javax.jws.WebMethod;



public interface TimeService



         String getTimeFromServer();



Step 2: SIB class


package com.javajee.ws.tsexample1;

import java.util.Date;

import javax.jws.WebService;

@WebService(endpointInterface =


public class TimeServiceImpl implements TimeService{

         public String getTimeFromServer(){

                 return new Date().toString();




Step 3: The publisher class using Endpoint publisher 


package com.javajee.ws.tsexample1;

import javax.xml.ws.Endpoint;


public class TimeServicePublisher {

  public static void main(String[] args)


      Endpoint endpoint = Endpoint.create(new TimeServiceImpl());





Step 4: Compile all classes and execute the publisher

You can compile all classes as:

javac com\javajee\ws\tsexample1\*.java

You can execute as:

java com.javajee.ws.tsexample1.TimeServicePublisher

You can now see the generated wsdl by typing below in browser:

You can see the style=document and use=literal in the wsdl denoting that this is a document / literal web service. You can also check the ‘targetNamespace’ and ‘name’ attributes of the definitions element which are needed for configuring a client manually.


Step 5: The client 


package com.javajee.ws.tsexample1;


import javax.xml.namespace.QName;

import javax.xml.ws.Service;

import java.net.URL;

import java.net.MalformedURLException;


class TimeClient {

         public static void main(String[] args) throws MalformedURLException


                 URL url = new URL("");

                 QName qname = new


                 Service service = Service.create(url,qname);

                 TimeService port = service.getPort(TimeService.class);

                 System.out.println("Current Time = "

                   + port.getTimeFromServer());        



You can execute the client class and see the result:

java com.javajee.ws.tsexample1.TimeClient


Additional Exercises

Try out these and verify the results.


Remove the @WebService annotation over the SEI (TimeService)


All classes will compile fine, but execution of the publisher will result in an error:

 … com.sun.xml.internal.ws.model.RuntimeModelerException: The Endpoint Interface: … does not have WebService Annotation


Remove the @WebService annotation over the SIB (TimeServiceImpl)


All classes will compile fine, but execution of the publisher will result in an error:

java.lang.IllegalArgumentException: … TimeServiceImpl has neither @WebService nor @WebServiceProvider annotation


Remove implements TimeService from the SIB declaration


Classes will compile and run fine.


It is not required for the SIB to implement the SEI, after linking SIB to SEI through the webservice annotation’s endpointInterface parameter.

However, it is unsafe not to implement. By having the implements clause, compiler checks whether the SIB implements the methods declared in the SEI.


Remove @WebMethod from the method declared in the SEI TimeService


Same behaviour


@WebMethod is optional for a method exposed as a web service, but can be used to make a method as not exposed as a web method.

References and notes: 

Endpoint publisher

  • The java.xml.Endpoint class can be used to publish a web service from a simple java application.

  • Out of the box, the Endpoint publisher handles one request at a time, but can be made multithreaded using an Executor.

  • The single threaded endpoint publisher is suited for development and the multithreaded one can be used in light production mode.

  • However a web container such as tomcat is better suited to publish multiple web services in actual production.

Quick Notes Finder Tags

Activities (1) advanced java (1) agile (3) App Servers (6) archived notes (2) ArrayLists (1) Arrays (2) Best Practices (12) Best Practices (Design) (3) Best Practices (Java) (7) Best Practices (Java EE) (1) BigData (3) Chars & Encodings (6) coding problems (2) Collections (15) contests (3) Core Java (All) (53) course plan (2) Database (12) Design patterns (8) dev tools (3) downloads (2) eclipse (9) Essentials (1) examples (14) Exception (1) Exceptions (4) Exercise (1) exercises (6) Getting Started (18) Groovy (2) hadoop (4) hibernate (77) hibernate interview questions (6) History (1) Hot book (5) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (8) java ee exercises (1) java ee interview questions (2) Java Elements (16) Java Environment (1) Java Features (4) java interview points (4) java interview questions (4) javajee initiatives (1) javajee thoughts (3) Java Performance (6) Java Programmer 1 (12) Java Programmer 2 (8) Javascript Frameworks (1) Java SE Professional (1) JPA 1 - Module (6) JPA 1 - Modules (1) JSP (1) Legacy Java (1) linked list (3) maven (1) Multithreading (16) NFR (1) No SQL (1) Object Oriented (9) OCPJP (4) OCPWCD (1) OOAD (3) Operators (4) Overloading (2) Overriding (2) Overviews (1) policies (1) programming (1) Quartz Scheduler (1) Quizzes (17) RabbitMQ (1) references (2) resources (1) restful web service (3) Searching (1) security (10) Servlets (8) Servlets and JSP (31) Site Usage Guidelines (1) Sorting (1) source code management (1) spring (4) spring boot (3) Spring Examples (1) Spring Features (1) spring jpa (1) Stack (1) Streams & IO (3) Strings (11) SW Developer Tools (2) testing (1) troubleshooting (1) user interface (1) vxml (8) web services (1) Web Technologies (1) Web Technology Books (1) youtube (1)