Java Web Services Interview Questions

What are web services ?

Web services  are client and server applications that communicate over the World Wide Web’s (WWW) HyperText Transfer Protocol (HTTP). Web services provide a standard means of inter operating between software applications running on a variety of platforms and frameworks.

Main characteristics of the Web Services  are :
1. Interoperability
2. Extensibility
3. Machine processable descriptions.

for example in simple words , when we call somebody so the person dialing and calling is the client  application , while person receiving the call is server applicationand “hello” word is the protocol as similar to HTTP request .

What is the difference between SOA and a web service?

SOA (Service-Oriented Architecture) is an architectural pattern that makes possible for

services to interact with one another independently.

Web Services is a realization of SOA concept, that leverages XML, JSON, etc. and common Internet protocols such as HTTP(S), SMTP, etc.

SOA is a system-level architectural style that tries to expose business. WOA is an interface-level architectural style that focuses on the means by which these service capabilities are exposed to consumers.

What is SOAP?

SOAP (Simple Object Access Protocol) is a transport protocol for sending and receiving requests and responses on XML format, which can be used on top of transport protocols such as HTTP, SMTP, UDP, etc.

What is REST?

REST (REpresentational State Transfer) is an architectural style by which data can be transmitted over transport protocol such as HTTP(S).

What is the difference between a REST web service and a SOAP web service?

Below are the main differences between REST and SOAP web service

  • REST supports different formats like text, JSON and XML; SOAP only supports XML;
  • REST works only over HTTP(S) on a transport layer; SOAP can be used different protocols on a transport layer;
  • REST works with resources, each unique URL is some representation of a resource; SOAP works with operations, which implement some business logic through different interfaces;
  • SOAP based reads can’t be cached, for SOAP need to provide caching; REST based reads can be cached;
  • SOAP supports SSL security and WS-security(Web Service-security); REST onlysupports SSL security;
  • SOAP supports ACID(Atomicity, Consistency, Isolation, Durability); REST supports transactions, but it is neither ACID compliant nor can provide two phase commit.

How to decide which one of web service to use REST or SOAP?

“REST vs SOAP” we can rephrased to “Simplicity vs Standard”. Of course, “Simplicity” with REST at most cases wins, it wins in performance, scalability and support for multiple data formats, but SOAP is favored where service requires comprehensive support for security (WS-security) and transactional safety (ACID).

What is WSDL?

WSDL (Web Services Description Language) is an XML format for describing web services and how to access them.

What is JAX-WS?

JAX-WS (Java API for XML Web Services) is a set of APIs for creating web services in XML format.

What is JAXB?

JAXB (Java Architecture for XML Binding) is a Java standard that defines how Java objects are converted from and to XML. It makes reading and writing of XML via Java relatively easy.

Can we send soap messages with attachments?

Yes, we can send different formats such as PDF document, image or other binary file with soap messages as an attachment. Messages send using the binary data. SOAP messages is attached with MIME extensions that come in multipart/related.

An example:

MIME-Version: 1.0

Content-Type: Multipart/Related; boundary=MIME_boundary; type=text/xml;

start=”<[email protected]>”

Content-Description: This is the optional message description.

<?xml version=’1.0′ ?>




<theSignedForm href=”cid:[email protected]”/>




Content-Type: image/tiff

Content-Transfer-Encoding: binary

Content-ID: <[email protected]>

…binary TIFF image…


Best Python Training

Get Started to become a hands-on expert on Python!

What is MTOM?

MTOM (Message Transmission Optimization Mechanism) is a mechanism for transmitting large binary attachments with SOAP messages as raw bytes, allowing for smaller messages.

What is XOP?

XOP (XML-binary Optimized Packaging) is a mechanism defined for the serialization of XML Information Sets that contain binary data, as well as deserialization back into the XML Information Set.

What is a SOAP envelope element?

SOAP envelop element is the root element of a SOAP message which defines the XML document as a SOAP message.

An example:

<?xml version=”1.0″?>




Message information


What does a SOAP namespace defines?

SOAP namespace defines the Envelope as a SOAP Envelope.

An example:


What is the SOAP encoding?

SOAP encoding is a method for structuring the request which is suggested within the SOAP specification, known as the SOAP serialization.

What does SOAP encodingStyle attribute defines?

SOAP encodingStyle defines the serialization rules used in a SOAP message. This attribute may appear on any element, and is scoped to that element’s contents and all child elements not themselves containing such an attribute. There is no default encoding defined for a SOAP message.

An example: 


What are 2 styles web service’s endpoint by using JAX-WS?

  • RPC (remote procedure call) style web service in JAX-WS;
  • document style web service in JAX-WS.

What is encoding rules for header entries?

  • a header entry is identified by its fully qualified element name, which consists of the namespace URI and the local name. All immediate child elements of the SOAP Header element must be namespace-qualified.
  • the SOAP encodingStyle attribute may be used to indicate the encoding style used for the header entries.
  • the SOAP mustUnderstand attribute and SOAP actor attribute may be used to indicate how to process the entry and by whom.

What is the wsimport tool?

The wsimport tool is used to parse an existing Web Services Description Language (WSDL) file and generate required files (JAX-WS portable artifacts) for web service client to access the published web services:

What is the wsgen tool?

The wsgen tool is used to parse an existing web service implementation class and generates required files (JAX-WS portable artifacts) for web service deployment:


What the tool are required to test SOAP services?

SOAPUI tool for SOAP WS:

What is the difference between SOAP and other remote access techniques?

  • SOAP is simple to use and it is non – symmetrical unlike DCOM or CORBA is highly popular and usually have complexity in them.
  • SOAP provides greater platform independent with the language independence unlike DCOM or CORBA doesn’t provide any of these.
  • SOAP uses HTTP as its transport protocol and the data are being saved in XML format that can be ready by human, whereas DCOM or CORBA have their own binary formats that are used to transport the data in complicated manner.
    SOAP identify the object other than URL endpoint. SOAP objects are stateless and it is hard to maintain that. Whereas, it is not hard to maintain in case of other remote access techniques.

What is a resource in a REST?

A resource is a unique URL with representation of an object which we can get contents via GET and modify via PUT, POST, DELETE.

What are HTTP methods supported by REST?

  • GET;
  • POST;
  • PUT;

Whether can use GET request instead of POST to create a resource?

It is not possibly, because GET can’t change a resource.\

What is the difference between PUT and POST?

Need to use PUT when can update a resource completely through a specific resource. For example, if know that an article resides at, can PUT a new resource representation of this article through a PUT on this URL. If do not know the actual resource location for instance, when add a new article, can use POST.

PUT is idempotent, while POST is not. It means if use PUT an object twice, it has no effect.

What is WADL?

WADL (Web Application Description Language) is a XML description of a deployed RESTful web application.

What are frameworks available to implement REST web services?

Jersey, Restlet, EasyRest, etc.

What is the Restlet framework?

Restlet is a lightweight, comprehensive, open source RESTful web API framework for the Java platform.

It has advantages such as

  • websocket and server-sent events support;
  • HTTP/2 support;
  • transparent HTTP PATCH support;
  • client cache service;
  • fluent APIs.

What is the Jersey framework?

Jersey is open source framework for developing RESTful Web Services in Java that provides support for JAX-RS APIs and serves as a JAX-RS (JSR 311 & JSR 339) Reference Implementation. It has advantages such as

  • contains support for Web Application Description Language (WADL);
  • contains Jersey Test Framework which lets run and test Jersey REST services inside JUnit;
  • supports for the REST MVC pattern, which would allow to return a View from Jersey services rather than just data.

What is the REST easy framework?

RESTeasy is a JBoss project, which implements of the JAX-RS specification. It has benefits such as

  • fully certified JAX-RS implementation; supports HTTP 1.1 caching semantics including cache revalidation;
  • JAXB marshalling into XML, JSON, Jackson, Fastinfoset, and Atom as well as wrappers for maps, arrays, lists, and sets of JAXB Objects;
  • OAuth2 and Distributed SSO with JBoss AS7;
  • rich set of providers for: XML, JSON, YAML, Fastinfoset, Multipart, XOP, Atom, etc.

What is the difference between AJAX and REST?

  • in Ajax, the request are sent to the server by using XMLHttpRequest objects; REST have a URL structure and a request/response pattern the revolve around the use of resources;
  • Ajax eliminates the interaction between the customer and server asynchronously; REST requires the interaction between the customer and server;
  • Ajax is a set of technology; REST is a type of software architecture and a method for users to request data or information from servers.

What tool are required to test REST services?

Firefox “poster” plugin for RESTFUL services.

What does a @Path annotation do?

@Path annotation binds URI pattern to a Java method.





public class PersonRestService {


public Response getPerson() {

return Response.status(200).entity(“getPerson is called”).build();




public Response getPersonVIP() {

return Response.status(200).entity(“getPersonVIP is called”).build();



On calling URI: “/persons” result:  getPerson is called

On calling URI: “/persons/vip” result:  getPersonVIP is called

What does a @PathParam do?

@PathParam annotation injects the value of URI parameter that defined in @Path expression.






public class PersonRestService {



public Response getPersonById(@PathParam(“id”) String id) {

return Response.status(200).entity(“getPersonById is called, id : ” + id).build();



On calling URI: “/persons/1” result:  getPersonById is called, id : 1

What is new in this field for past few years?

The initiation of XML in this field is the advancement that provides web service a single language to communicate in between the RPCs, web services and their directories.

Give me an example of real web service?

One example of web services is IBM Web Services browser. You can get it from IBM Alphaworks site. This browser shows various demos related to web services. Basically web services can be used with the help of SOAP, WSDL, and UDDI . All these, provide a plug-and-play interface for using web services such as stock-quote service, a traffic-report service,  weather service etc.

How you define web service protocol stack?

It is basically set of various protocols that can be used to explore and execute web services. The entire stack has four layers i.e. Service Transport, XML Messaging, Service Description and Service Discovery.

Can you define each of these layers of protocol stack?

The Service Transport layer transfer messages between different applications, such as HTTP, SMTP, FTP, and Blocks Extensible Exchange Protocol (BEEP). The XML Messaging layer encodes messages in XML format so that messages can be understood at each end, such as XML-RPC and SOAP. The Service Description layer describes the user interface to a web service, such as WSDL. The Service Discovery layer centralizes services to a common registry and offer simple publish functionality, such as UDDI.

Define XML – RPC?

It is a protocol that makes use of XML messages to do Remote Procedure Calls.

Define WSDL?

It means Web Services Description Language. It is basically the service description layer in the web service protocol stock. The Service Description layer describes the user interface to a web service.

What kind of security is needed for web services?

 The security level for web services should be more than that of what we say Secure Socket Layer (SSL). This level of security can be only achieved from Entrust Secure Transaction Platform. Web services need this level of security to ensure reliable transactions and secure confidential information .

Do you have any idea about foundation security services?

As implies from its name, these services are the foundation or basics of integration, authentication, authorization, digital signatures and encryption processes.

Define Entrust Identification Service?

Entrust Identification Service comes from the Entrust Security Transaction Platform. This platform allows companies to control the identities that are trusted to perform transactions for Web services transactions.

What UDDI means?

UDDI stands for Universal, Description, Discovery, and Integration. It is the discovery layer in the web services protocol stack.

Define Entrust Entitlements Service?

This service verifies entities that attempt to access a web service. For Example, the authentication service, the Entitlements Service ensures security in business operations.

Define Entrust Privacy Service?

As its name implies, it deals with security and confidentiality. This service encrypts data to ensure that only concerned parties can access the data.

What do you mean by PKI?

It means Public-Key Infrastructure.

What tools are used to test a web service?

I have used SoapUI for SOAP WS and Firefox poster plugin for RESTFul Services.

Differentiate between a SOA and a Web service?

SOA is a design and architecture to implement other services. SOA can be easily implemented using various protocols such as HTTP, HTTPS, JMS, SMTP, RMI, IIOP, RPC etc. While Web service, itself is an implemented technology. In fact one can implement SOA using the web service.

Discuss various approaches to develop SOAP based web service?

We can develop SOAP based web service with two different types of approaches such as contract-first and contract-last. In the first approach, the contract is defined first and then the classes are derived from the contract while in the later one, the classes are defined first and then the contract is derived from these classes.

If you have to choose one approach, then what will be your choice?

In my point of view, the first approach that is the contract-first approach is more feasible as compared to the second one but still it depends on other factors too.

Is there any special application required to access web service?

No, you don’t need to install any special application to access web service. You can access web service from any application that supports XML based object request and response.

Can you name few free and commercial implementations for web services?

The implementations I know are Apache SOAP, JAX-WS Reference Implementation, JAX-RS Reference Implementation, Metro, Apache CXF, MS.NET and Java 6.

Name browser that allows access to web service?

JavaScript XmlHttpRequest object is required to access web service via browsers. The browsers that support this object are Internet Explorer, Safari and Mozilla-based browsers like FireFox.

What is REST?

REST stands for Representational State Transfer. REST itself is not a standard, while it uses various standards such as HTTP, URL, XML/HTML/GIF/JPEG (Resource Representations) and text/xml, text/html, image/gif, image/jpeg, etc (MIME Types).

How one can provide API to users?

To provide an API to the users, one can easily do this with an “open table”. All you need to do is to write open table which is basically an XML schema that point to a web service.

Name the various communication channels in web service?

Web service is integrated with three protocols such as HTTP/POST, HTTP/GET, and SOAP. It provides three different communication channels to clients. Client can choose any communication method as per requirements.

How can you document web service?

Web services are contemplated as self-documenting because they provide entire information regarding the available methods and parameters used for XML based standard, known as WSDL. One can also provide more information to explain web services via their own Web Service and Web Method attributes.

What are the situations, when we need ASP.NET web services?

ASP.NET web services are used when one need to implement three tier architecture in a web service. It allows handy ways to use middle tier components through internet. The main advantage of .NET Web services is that they are capable enough to communicate across firewalls because they use SOAP as transport protocol.


The increasing ratio of distributed applications has raised demand for distributed technologies. It allows segmenting of application units and transferring them to different computers on different networks.

Differentiate between web services, CORBA and DCOM?

Web services transfer/receive messages to/from application respectively, via HTTP protocol. It uses XML to encode data.

CORBA and DCOM transfer/receive messages to/from application respectively, via non-standard protocols such as IIOP and RPC.

Can you tell few benefits of web services?

The biggest advantage of web service is that is supported by wide variety of platforms. Moreover, in near future, web services may spread its boundary and enhance new methods that will provide ease to clients. The enhancement will not affect the clients, even if they offer old methods and parameters.

Can you name some standards used in web services?

The standards used in web services are WSDL (used to create interface definition), SOAP (used to structure data), HTTP (communication channels), DISCO (used to create discovery documents) and UDDI (used to create business registries).

Explain in brief, what DISCO is?

DISCO means discovery. It groups the list of interrelated web services. The organization that provides web services, issues a DISCO file on its server and that file contains the links of all the provided web services. This standard is good when client knows the company already. Also it can be used within a local network as well.

Explain in brief, what UDDI is?

UDDI (Universal Description, Discovery, and Integration) provides consolidated directory for web services on the internet. Clients use UDDI to find web services as per their business needs. It basically hosts the web services from various companies. In order to share web services, you need to publish it in UDDI.

Explain the .NET web services supported data types?

.Net web services uses XML-based standards to transfer/receive information. Thus, .NET web services can only works with data types known by XML schema standard. Like FileSteam, Eventlog etc. are not recognized by the XML schema standards and hence, not supported in web services.

How a .NET web service is tested?

ASP.NET uses a test page routinely, when one calls for the URL of .asmx file in any browser. This page shows complete information regarding web services.

How a .NET web service is consumed?

Since we know that web services are constructed on XML standards. Therefore, clients need to have complete understanding of XML-based messages to interchange messages. Clients can communicate with web services through .NET framework that offers proxy mechanisms. These proxy mechanisms have detailed information regarding data sharing within web services that can be easily used by the clients.

Can you name the two Microsoft solutions for distributed applications?

The two Microsoft solutions for distributed applications are .NET Web Services and .NET Remoting.

Differentiate between .NET Web Services and .NET Remoting?

As far as protocol is concerned, .NET Web Service uses HTTP, while, .NET Remoting uses any protocol i.e. TCP/HTTP/SMTP. When it comes to performance, .NET Remoting is comparatively, faster than.NET Web Service. Also, as .NET Web Services are hosted via IIS, therefore, it is far more reliable than the .NET Remoting.

Name the components to be published while deploying a Web Service?

The components that need to be published during a web service deployment are Web Application Directory, Webservice.asmx File, Webservice.Disco File, Web.Config File and Bin Directory.

What are the steps performed by the client to access a web service?

First of all a web reference to the web service is created by the client in his application. Then a proxy class is generated. After that an object of the proxy class is created and at last, the web service is accessed via that proxy object.

How web services are implemented in .NET?

To implement web services in .NET, HTTP handlers are used that interrupt requests to .asmx files.

Explain few disadvantages of Response Caching?

Response Caching is useless or incompetent when method accepts extensive amount of values because caching means to store lot of information.  Also, if the method depends on external source of information, and that are not provided within the parameters then such methods are bypassed.

What is the alternate solution to Response Caching?

One can use Data Caching (System.Web.Caching.Cach) instead of Response Caching.

Brief few drawbacks of using GET and POST methods to communicate with the web service?

These methods are less secure and inhibit users to pass structures and objects as arguments. Also, it doesn’t allow users to pass ByRef arguments.

How can one access a class as a web service?

To access a class as a web service, one should inherit the class from the System.Web.Services.WebService class and qualify the class with the WebService attribute.

How can one access the web service class method via internet?

To access web service class method via internet, one should qualify a method with the WebMethod attribute.

How a SOAP message is structured?

A SOAP message is consists of SOAP Envelope, SOAP Headers, and SOAP Body.

Can you name different kinds of web services?

There are two types of web services in total i.e. SOAP based web service and RESTful web service.

This question is already mentioned earlier.

What’s different in RESTful web services?

The RESTful web services contains no contract or WSDL file.

Give me few reasons to use RESTful web service?

The RESTFul web services are simple to implement and test. It supports various data formats such as XML, JSON etc.

Explain what is JAVA web services? What are the methods to create web services?

Java webservices is developed to build and deploy basic web service on JAVA platform.

To create a web services, there are two approaches that are adopted

  • Top-down approach
  • Top-up approach

Explain what is JAXP?

JAXP is a JAVA API for XML processing that enables application to write, read, manipulate and transform XML data.  Similarly, to perform other various function there are other Java API’s as well like JAX-RPC, JAXM, JAXR, JAXB, etc.

Mention the JAXB binding framework?

JAXB binding framework is available in three Java Packages

  • bind:This package defines abstract classes and interfaces that are used directly with content classes
  • bind.util:This package contains utility classes that may be availed by client applications to manage marshalling, unmarshalling and validation events
  • bind.helper:This helper package gives partial implementations for some of the javax.xml.bind interfaces. These APIs are not to be directly used by applications using JAXB architecture

Give a simple example of how XML document can be Marshal and Unmarshal in JAVA framework?

Marshalling is the process of converting XML document into Java readable form while UnMarshalling is the reverse process of Marshalling.  Let see how Java unmarshals an XML document and then marshals it back

JAXBContext jc= JAXBContext.newInstance (“”);

// unmarshal from foo.xml

Unmarshaller u = jc.createUnmarshaller () ;

FooObject fooObj=

(FooObject)u.unmarshal (new File (“foo.xml”) );

// marshal to sytem.out

Marshaller m = jc.createMarshaller ();

m.marshal (fooObj, System.out);

Explain what does Marshaller do if jaxb.encoding property is not declared?

By default, the Marshaller will use “UTF-8” if jaxb.encoding property is not declared.

Mention what are the types of validation can a JAXB client can perform?

There are two types of JAXB client validation that a JAXB can perform

  • Unmarshal Time Validation
  • On-Demand Validation

Mention what are the three ways to handle the event encountered during the marshal, unmarshal and validate operations?

  • Using the default event handler
  • Register and Implement a custom event handler
  • Use the ValidationEventCollector utility

Explain where does JAXB compiler is located?

JAXB schema binding compiler is placed in the <JWSDP_Home>/jaxb/bin directory.  In this directory, there are two scripts, (Solaris/Linux) and xjc.bat (Windows).

In what cases do you need to customize the default binding?

In some cases, you are required to customize the default binding like

  • Creating API documentation for the schema derived JAXB packages, classes, methods and constants
  • Giving semantically meaningful customized names for cases that the default XML name-to-Java identifier mapping cannot handle automatically
  • Overriding default binding- like specifying that a model group should be attached to a class rather than a list

Explain what is Inline Customization?

Customization to JAXB bindings made by means of inline binding declarations  in an XML schema file that take the form of <xsd:appinfo> elements embedded in schema <xsd:annotation>elements.

Explain what is XML signature?

XML can be used to sign any arbitrary data whether it is a binary or XML.  The data is recognized via URIs in one or more reference elements.  It is described in one or more forms, like detached, enveloping or enveloped.

Explain what is Stax?

Stax stands for Streaming API for XML; it is an API to read and write XML documents, originating from the JAVA programming language.

Mention what are the usual XML APIs?

The usual XML APIs includes

  • DOM based or Tree based APIs:The whole document is read into memory as a tree structure for random availability by calling application
  • Event based APIs:The application registers to get events as entities are encountered within the source document

Explore best ever Courses on Machine Learning

Change Your Career. Change Your Life. Now!

Explain what is Push parsing and Pull parsing?

  • Pull Parsing:Streaming pull parsing is referred to a programming model in which a client application calls methods on an XML parsing library, when it needed to communicate with an XML infoset- which means the client will only gets XML data when it is asked for
  • Push Parsing:In Push Parsing, the parser pushes parsing events or XML data to the application.  In push model, the parser got the hold over the parsing  process and the parser calls the implemented handler methods.

Explain on which technology does XWS security is based on? List out the options that XWS security provides for securing JAX-RPC applications?

XWS security is based on securing web services build on JAX-RPC and on stand-alone application based on SAAJ.  For securing JAX-RPC application, options that XWS security provides are

  • XML digital signature
  • XML encryption
  • Username token verification
  • XWS security framework APIs

List out the six packages available in XML Digital signature API?

Digital signature API is

  • crypto
  • crypto.dsig
  • crypto.dsig.keyinfo
  • crypto.dsig.spec
  • crypto.dom
  • crypto.dsig.dom

Explain what is JAXR?

JAXR is the JAVA programming APIs for Java platform application to access and programmatically interact with various kinds of meta-data registries.

Explain what does the JAXR architecture consist of?

JAXR architecture is consists of a JAXR client and JAXR provider.

  • JAXR client:It is a client program which uses the JAXR API to use a registry through a JAXR provider
  • JAXR provider:It is an implementation of the JAXR API that provide access to a particular registry provider or to a class of registry providers that are built on a common speicifications.

Explain what is JAXM messaging models?

There are two types of messaging models for JAXM synchronous and asynchronous

  • Synchronous messaging model:In such type of model, client directly communicates with the source. In this, the client will send the request and waits.
  • Asynchronous messaging model:In this model, client directs the message to the messaging provider and returns back.  Messaging provider then executes the routing of the message to the end source.

Explain what is UDDI, DISCO and WSDL?

  • UDDI:It means Universal Description, Discovery and I It is the directory that is used to publish and discover public web services
  • DISCO:It is commonly known as discovery. It clubs common services together and exposes schemas document of the web services
  • WSDL:It stands for web service description language (WSDL). It is used to describe web services.  The description includes URL of web services, properties and methods supported by web services, data type it supports and protocol detail it supports

You may be interested in