Table of contents
1.
Introduction 
2.
JAX-WS
2.1.
RPC web service
2.2.
Document style web service
3.
Creating a SOAP Web service
3.1.
WSDL
4.
Frequently Asked Questions
4.1.
Why does JAX-SW use annotations?
4.2.
Name the command-line tools for generating portable artefacts for JAX-WS web services.
4.3.
What is the @WebService annotation?
5.
Conclusion
Last Updated: Mar 27, 2024
Easy

Introduction to JAX-WS

Author Yashesvinee V
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction 

SOAP and REST are the two types of web services offered over the internet. Java’s very own APIs are used to create both these services. JAX-WS is one such API which stands for Java API for XML Web Services. It is an XML-based Java API to build web services for client-server applications. They come as part of the JDK installation and extensively use annotations.

Introduction to JAX-WS

Recommended Topic, procedure call in compiler design

JAX-WS

JAX-WS is a framework that simplifies the creation and use of SOAP APIs. It is a programming model for application development that uses annotations thoroughly. Web services are called both synchronously and asynchronously with JAX-WS. It supports a polling and callback mechanism for asynchronous calls to web services. In the polling model, a client can issue a request and get a response back. This is polled to determine if the server has responded to the client's request and to retrieve the actual response. In the callback model, the client provides a callback handler to receive and process the response object. Both models enable a client to focus on process work without waiting for a response. JAX-WS web services can be created by using either a WSDL file or an implementation bean class as a start.

JAX-WS

RPC web service

RPC or Remote Procedure Call is used to construct distributed, client-server-based applications. One procedure calls another procedure, both existing in different address spaces. JAX-WS RCP can invoke a Java-based Web service with a known description and a consistent WSDL description. The SOAP messages body contains an XML representation of the method’s call. The method name and parameters construct an XML tree representing the method’s call stack.

Document style web service

The Document style web service is also referred to as the Message-Oriented style. The SOAP message body contains an XML document that can be validated against a predefined XML schema. Since the protocol relies on the predefined schema to determine the structure of the SOAP message, it is customisable and flexible.

Creating a SOAP Web service

There are two approaches to building SOAP web services using JAX-WS. The top-down approach and the bottom-up approach. In a top-down approach, all necessary Java classes are generated from a WSDL file. In a bottom-up approach, the Java classes are written based on which a  WSDL file is generated.

The complexity of writing a WSDL file depends on the web service required. Hence, the bottom-up approach is a prefered option. However, if the code in the Java classes change, the generated WSDL will also change. This can be prevented if the top-down approach is used.

WSDL

WSDL stands for Web Services Description Language and describes a web service. A WSDL document is written in XML format to describe the interface provided by a web service provider. WSDL has six main elements:

  • The definitions element is the root element that defines the name, namespace, etc.
     
  • The types element defines all the data types used by the web service. 
     
  • The message element defines an abstract of the transmitted data. 
     
  • The portType element includes the operations and the message elements involved with it. 
     
  • The binding element provides protocol and data format details for each portType.
     
  • The service element defines details on the ports supported by the web service. 

Frequently Asked Questions

Why does JAX-SW use annotations?

JAX-WS supports annotation of Java classes with metadata which indicates that the class is a Web service. Annotations are used to expose Java artefacts as web services. It also supports web services development within a team structure and enables parallel development of the service with the required metadata.

Name the command-line tools for generating portable artefacts for JAX-WS web services.

The wsgen and wsimport are two command-line tools for generating portable artefacts for JAX-WS web services. Wsgen is used when a web service is created, starting with an implementation bean class. For a WSDL file, wsimport is used.

What is the @WebService annotation?

The @WebService annotation tells the server runtime environment to expose all related public methods as a web service. This annotation indicates that a Java class is implementing a Web service. Any Java class that implements a web service must have either the @WebService or the @WebServiceProvider annotation.

Conclusion

This blog gives an introduction to JAX-WS web services. It also discusses the two ways of implementing JAX-WS, i.e. RPC and Document style. Check out our articles on Types of web servicesJava Web Services and SOAP API. Explore our Library on Coding Ninjas Studio to gain knowledge on Data Structures and Algorithms, Machine Learning, Deep Learning, Cloud Computing and many more! Test your coding skills by solving our test series and participating in the contests hosted on Coding Ninjas Studio! 

Looking for questions from tech giants like Amazon, Microsoft, Uber, etc.? Look at the problems, interview experiences, and interview bundle for placement preparations. Upvote our blogs if you find them insightful and engaging! Happy Coding!

Thank you

Live masterclass