DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Migrate, Modernize and Build Java Web Apps on Azure: This live workshop will cover methods to enhance Java application development workflow.

Modern Digital Website Security: Prepare to face any form of malicious web activity and enable your sites to optimally serve your customers.

Kubernetes in the Enterprise: The latest expert insights on scaling, serverless, Kubernetes-powered AI, cluster security, FinOps, and more.

E-Commerce Development Essentials: Considering starting or working on an e-commerce business? Learn how to create a backend that scales.

Related

  • 5 Annotations Every Java Developer Should Know
  • The Developer's Guide to Collections: Queues
  • The Developer's Guide to Collections: Sets
  • The Developer's Guide to Collections

Trending

  • Java 21 Is a Major Step for Java: Non-Blocking IO and Upgraded ZGC
  • Micro-frontends Using React: The Complete Guide
  • The Role of Metadata in Data Management
  • How To Create an Analytical Dashboard With Next.js: Airline Dashboard Example
  1. DZone
  2. Coding
  3. Java
  4. JAX-WS Five-Minute Tutorial

JAX-WS Five-Minute Tutorial

This tutorial is for people who want to run a JAX-WS example (Endpoint + Client) in just five minutes.

Mohammad Juma user avatar by
Mohammad Juma
·
Aug. 08, 19 · Tutorial
Like (7)
Save
Tweet
Share
313.6K Views

Join the DZone community and get the full member experience.

Join For Free

What you need to run this example:

  1. JDK 1.6
  2. Eclipse
  3. Be Excited ;)

Note: You can download the source code for this example from the section.

Developing WebService End Point

1) Open Eclipse and create a Java project "WS-Server".

2) Create WS-Service Endpoint Interface:

package juma.mohammad;import javax.jws.WebMethod;import javax.jws.WebService;@WebServicepublic interface Greeting { @WebMethod String sayHello(String name);}

3) Create WS-Service Endpoint Implementation class:

package juma.mohammad;import javax.jws.WebService;@WebService(endpointInterface = "juma.mohammad.Greeting")public class GreetingImpl implements Greeting {@Overridepublic String sayHello(String name) {return "Hello, Welcom to jax-ws " + name;}}

4) Create Endpoint Publisher class:

package juma;import javax.xml.ws.Endpoint;import juma.mohammad.GreetingImpl;public class WSPublisher {public static void main(String[] args) {Endpoint.publish("http://localhost:8080/WS/Greeting",new GreetingImpl());}}

5) Run the WSPublisher. Guess what...your WebService is published.
Wow, check your service wsdl http://localhost:8080/WS/Greeting?wsdl

Developing WebService Client

1) Open eclipse and create a new Java project "WS-Client".

2) As you know, we need to generate the client stubs...but how?

Open your command line and enter the wsimport command:

CD %CLIENT_PROJECT_HOME%\srcwsimport –s . http://localhost:8080/WS/Greeting?wsdl

You will find 6 Java classes generated and compiled under src/juma/mohammad.

You can remove *.class files;  there's no need for them :)

3) Now let's create Client Class, which will be dependent on the stubs:

package juma;import juma.mohammad.Greeting;import juma.mohammad.GreetingImplService;public class Client {public static void main(String[] args){GreetingImplService service = new GreetingImplService();Greeting greeting = service.getGreetingImplPort(); System.out.println("------->>  Call Started");System.out.println(greeting.sayHello("Ali"));System.out.println("------->>  Call Ended");}}

4) Run the Client Class....the output should look like:

------->>  Call StartedHello, Welcom to jax-ws Ali------->>  Call Ended

Congratulations! You managed to develop jax-ws Endpoint, Client.

The next tutorial will show how to deploy your Web Service on Tomcat.

Web Service Java (programming language) Eclipse Command (computing) Java Development Kit Apache Tomcat Interface (computing) Implementation

Opinions expressed by DZone contributors are their own.

Related

  • 5 Annotations Every Java Developer Should Know
  • The Developer's Guide to Collections: Queues
  • The Developer's Guide to Collections: Sets
  • The Developer's Guide to Collections

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: