<div dir="ltr" style="text-align: justify;">In this tutorial we want to run a <i><b>JAX-WS</b></i> example (<b>Endpoint + Client</b>) for beginner of<b><i> JAX-WS</i></b> web service give the few minutes to this tutorial and happy learning ; ) .</div>
<div dir="ltr"></div>
<div dir="ltr" style="text-align: justify;"><b>Prerequisites:</b></p>
<ol>
<li>JDK 1.6</li>
<li>Eclipse (or STS) IDE</li>
</ol>
<h2><b>Developing <i>WebService </i>End Point</b></h2>
<p>1) Open Eclipse (or STS), and create a java project &#8220;<i><b>JAXWSServerHello</b></i>&#8220;.</p>
<div class="separator" style="clear: both; text-align: center;"></div>
<div id="ads-id" align="center"></div>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2013/06/step1ws.png" border="0" /></div>
<p><b>2) Create <i>WSServiceHello </i>Endpoint Interface:</b></p>
<div id="ads-id" align="center"></div>
<div class="separator" style="clear: both; text-align: center;"></div>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2013/06/step2ws.png" border="0" /></div>
<p><b><b><i>WSServiceHello .java</i></b></b></p>
<pre class="highlight">package com.dineshonjava.ws; 
 
import javax.jws.WebMethod; 
import javax.jws.WebService; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
@WebService 
public interface WSServiceHello { 
 
 @WebMethod String sayHello(String name); 
 
} 
</pre>
<p><b>3) Create <i>WSServiceHello </i>Endpoint Implementation class:</b><br />
<b><b><i>WSServiceHello .java</i></b></b></p>
<pre class="highlight">package com.dineshonjava.ws; 
 
import javax.jws.WebService; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
@WebService(endpointInterface="com.dineshonjava.ws.WSServiceHello") 
public class WSServiceHelloImpl implements WSServiceHello { 
 
 @Override 
 public String sayHello(String name) { 
 return "Hello, Welcome to JAX-WS World and keep learning!! " + name; 
 } 
 
} 
</pre>
<p><b>4) Create Endpoint Publisher class:</b><br />
<b><i>WSHelloPublisher.java</i> </b></p>
<pre class="highlight">package com.dineshonjava.publisher; 
 
import javax.xml.ws.Endpoint; 
 
import com.dineshonjava.ws.WSServiceHelloImpl; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
public class WSHelloPublisher { 
 
 public static void main(String[] args) { 
 Endpoint.publish("http://localhost:8181/WS/WSServiceHello" 
 ,new WSServiceHelloImpl()); 
 } 
 
} 
</pre>
<p><b>5) Run above program.Your web service is published.You can check your service <i>wsdl </i>at<i> http://localhost:8181/WS/WSServiceHello?wsdl</i><br />
WSServiceHello.wsdl<br />
</b></p>
<pre class="highlight"><;?xml version="1.0" encoding="UTF-8"?>; 
<;!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. -->; 
<;!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. -->; 
<;definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.dineshonjava.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.dineshonjava.com/" name="WSServiceHelloImplService">; 
<;types>; 
<;xsd:schema>; 
<;xsd:import namespace="http://ws.dineshonjava.com/" schemaLocation="http://localhost:8181/WS/WSServiceHello?xsd=1"/>; 
<;/xsd:schema>; 
<;/types>; 
<;message name="sayHello">; 
<;part name="parameters" element="tns:sayHello"/>; 
<;/message>; 
<;message name="sayHelloResponse">; 
<;part name="parameters" element="tns:sayHelloResponse"/>; 
<;/message>; 
<;portType name="WSServiceHello">; 
<;operation name="sayHello">; 
<;input message="tns:sayHello"/>; 
<;output message="tns:sayHelloResponse"/>; 
<;/operation>; 
<;/portType>; 
<;binding name="WSServiceHelloImplPortBinding" type="tns:WSServiceHello">; 
<;soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>; 
<;operation name="sayHello">; 
<;soap:operation soapAction=""/>; 
<;input>; 
<;soap:body use="literal"/>; 
<;/input>; 
<;output>; 
<;soap:body use="literal"/>; 
<;/output>; 
<;/operation>; 
<;/binding>; 
<;service name="WSServiceHelloImplService">; 
<;port name="WSServiceHelloImplPort" binding="tns:WSServiceHelloImplPortBinding">; 
<;soap:address location="http://localhost:8181/WS/WSServiceHello"/>; 
<;/port>; 
<;/service>; 
<;/definitions>; 
</pre>
<p><b>Developing <i>WebService </i>Client :</b><br />
1) <b>Open eclipse(or STS</b>) and create a new java project <b>&#8220;WSHelloClient&#8221;</b></p>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2013/06/step3ws.png" border="0" /></div>
<p><b>2) As you know we need to generate the client stubs&#8230; but how? </b><br />
<b>open your command line, and enter the <i>wsimport </i>command:</b></p>
<pre class="highlight">CD %CLIENT_PROJECT_HOME%src 
wsimport -keep http://localhost:8181/WS/WSServiceHello?wsdl 
</pre>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2013/06/wscmd.png" border="0" /></div>
<p><b>you will find java classes generated and compiled under src->;com->;dineshonjava->;ws</b></p>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2013/06/wsclasses.png" border="0" /></div>
<p><b><br />
</b> <b>3) Lets create client class now.</b><br />
<b>create <i>WSHelloClient.java </i>under <i>src->;com.dineshonjava.client</i></b></p>
<pre class="highlight">package com.dineshonjava.client; 
 
import com.dineshonjava.ws.WSServiceHello; 
import com.dineshonjava.ws.WSServiceHelloImplService; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
public class WSHelloClient { 
 
 public static void main(String[] args) { 
 WSServiceHelloImplService service = new WSServiceHelloImplService(); 
 WSServiceHello serviceHello = service.getWSServiceHelloImplPort(); 
 System.out.println("***************Call Started*******************"); 
 System.out.println(serviceHello.sayHello("Dinesh")); 
 System.out.println("***************Call Ended*********************"); 
 } 
 
} 
</pre>
<p><b>4) Run above program and you will get following output.</b></p>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2013/06/wsoutput.png" border="0" /></div>
<p><b>Congratulation, you have successfully created web service endpoint and client. Now in <a href="https://dineshonjava.com/2013/05/creating-simple-web-service-and-clients.html" target="_blank" rel="noopener">next post</a>, we will deploy it on Tomcat.</b></p>
<h3><b>Download Source Code </b><br />
<b><a href="https://sites.google.com/a/dineshonjava.com/dineshonjava/dineshonjava/Source%20Code.zip?attredirects=0&;d=1" target="_blank" rel="noopener">SourceCode.zip</a></b></h3>
<p><i><b>References</b></i><br />
<i><b><a href="http://en.wikipedia.org/wiki/Web_service" target="_blank" rel="noopener">Wikipedia for Web Service</a></b></i></p>
<p> ;</p>
<div style="background-color: pink; border-width: thin; text-align: center;"><b><;<;<a href="https://dineshonjava.com/2013/06/jax-ws-web-service-tutorial.html">Previous</a> <;<; || <a href="https://dineshonjava.com/2013/01/core-java-baby-step-to-be-best-java-ian.html">Index </a>|| >;>;<a href="https://dineshonjava.com/2013/05/creating-simple-web-service-and-clients.html">Next</a> >;>;</b></div>
<p> ;</p>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/jax-ws-web-service-example-using/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/filenotfoundexception-in-eclipse-when/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '435'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…