Web Services Interview Questions
Web Services Interview Questions
In this series of interview questions about Architecture and Design, we cover interview questions related
to Architecture, Design, Design Patterns, Code Review, Performance and Load Testing, Web
Services, Restful Web Services, Security, Continous Integration and Java New Features
Interview Questions
Click Youtube Icon to Watch Now!!
1. What is a web service?
2. What are the important parts of a web service?
3. What are the advantages of Web Services?
4. What are the different types of web services?
5. What are SOAP Web Services?
6. What is a WSDL?
7. What is marshalling and unmarshalling? How do JAXB and XMLBeans help with this?
8. What are the java frameworks that you can use to build web services?
9. How do you handle security for Web Services?
10. What are the popular Java Specifications for Web services?
11. What is Service Oriented Architecture (SOA)?
Simplest definition is a service offered over the web (internet) i.e. HTTP. Whenever we browse the
internet, we are making use of innumerable web services. Even the simplest attempt to load a
google.com website involves web services.
When we type in google.com in the browser, following steps happen in the background:
Step II : google.com returns a HTTP response with the HTML content to show.
Step III : Browser understands the HTML content and renders it for the user.
Browser is invoking a get request and google.com server is responding with HTTP Response. This is a
great example of a web service.
Service Provider : Google.com is the service provider. Handles the request and sends a response
back.
Service Consumer : Browser is the service consumer. Creates Request. Invokes Service.
Processes the Response.
Data Exchange Format : In this example, Data Exchange is done over HTTP protocol. Request is
HTTP request and Response is HTTP Response. Data exchange format can be something else as
well. SOAP (in case of SOAP web services) and JSON (most RESTful services).
Re-use : Web services avoid the need to implement business logic repeatedly. If we expose a web
service, other applications can re-use the functionality
Modularity : For example, tax calculation can be implemented as a service and all the applications
that need this feature can invoke the tax calculation web service. Leads to very modular application
architecture.
Language Neutral : Web services enable communication between systems using different
programming languages and different architectures. For example, following systems can talk with
each other : Java, .Net, Mainframes etc.
Web Services are the fundamental blocks of implementing Service Oriented Architecture in an
organization.
SOAP Web Services : All web services using SOAP format (we will discuss this in detail later) are
called SOAP web services.
RESTful Web Services : All web services satisfying the Rest Architectural Constraints (we will
discuss this in detail too) are called RESTful Web Services.
In SOAP web services, data exchange (request and responses) happens using SOAP format. SOAP is
based on XML.
SOAP format defines a SOAP-Envelope which envelopes the entire document. SOAP-Header (optional)
contains any information needed to identify the request. Also, part of the Header is authentication,
authorization information (signatures, encrypted information etc). SOAP-Body contains the real xml
content of request or response.
All the SOAP web services use this format for exchanging requests and responses. In case of error
response, server responds back with SOAP-Fault.
What is a WSDL?
WSDL defines the format for a SOAP Message exchange between the Server (Service Provider) and the
Client (Service Consumer).
A WSDL defines the following
How can a service (operation) be called? What url to use? (also called End Point).
SOAP web services use SOAP based XML format for communication. Java applications work with beans
i.e. java objects. For an application to expose or consume SOAP web services, we need two things
JAXB and XMLBeans are frameworks which enable use to do marshalling and unmarshalling easily.
At transport level, SSL is used to exchange certificates (HTTPS). This ensures that the server
(service producer) and client (service consumer) are mutually authenticated. It is possible to use
one way SSL authentication as well.
Service Oriented is an architectural style where applications are built on top of language neutral, loosely
coupled, independent, reusable components.
Major components of SOA are
Business Process Layer : This represents the layer where the use cases are choreographed on top
of the Services.
Services Services and components used to build the services, such as various frameworks
All important questions regarding Restful web services are covered in this
- See more at: http://www.javainterview.in/p/web-services-interviewquestions.html#sthash.oqYACjy4.dpuf
Interview Questions
1. What is a REST Web Service?
2. What are important constraints for a RESTful Web Service?
3. What is Richardson Maturity Model?
4. What are the best practices in designing RESTful APIs?
5. What are the best practices in using HTTP methods with Restful Web Services?
6. Can you explain a little bit about JAX-RS?
7. What are the advantages of Restful web services?
8. What is the difference between REST and SOAP Based Services?
The interface (URL) is uniform and exposing resources. Interface uses nouns (not actions)
The service is stateless. Even if the service is called 10 times, the result must be the same.
Service should assume a Layered architecture. Client should not assume direct connection to
server - it might be getting info from a middle layer - cache.
Level 0 : Expose SOAP web services in REST style. Expose action based services
(http://server/getPosts, http://server/deletePosts, http://server/doThis, http://server/doThat etc) using
REST.
Level 1 : Expose Resources with proper URIs (using nouns). Ex: http://server/accounts,
http://server/accounts/10. However, HTTP Methods are not used.
Level 2 : Resources use proper URI's + HTTP Methods. For example, to update an account, you do
a PUT to . The create an account, you do a POST to . Uris look like posts/1/comments/5 and
accounts/1/friends/1.
Level 3 : HATEOAS (Hypermedia as the engine of application state). You will tell not only about the
information being requested but also about the next possible actions that the service consumer can
do. When requesting information about a facebook user, a REST service can return user details
along with information about how to get his recent posts, how to get his recent comments and how
to retrieve his friends list.
While designing any API, the most important thing is to think about the api consumer i.e. the client
who is going to use the service. What are his needs? Does the service uri make sense to him?
Does the request, response format make sense to him?
In Rest, we think Nouns (resources) and NOT Verbs (NOT actions). So, URIs should represent
resources. URIs should be hierarchical and as self descriptive as possible. Prefer plurals.
Always use HTTP Methods. Best practices with respect to each HTTP method is described in the
next question.
GET : Should not update anything. Should be idempotent (same result in multiple calls). Possible
Return Codes 200 (OK) + 404 (NOT FOUND) +400 (BAD REQUEST)
POST : Should create new resource. Ideally return JSON with link to newly created resource. Same
return codes as get possible. In addition : Return code 201 (CREATED) is possible.
PUT : Update a known resource. ex: update client details. Possible Return Codes : 200(OK)
@ApplicationPath("/"). @Path("users") : used on class and methods to define the url path.
@GET @POST : Used to define the HTTP method that invokes the method.
Useful methods:
Most Restful services use HTTP protocol : Entire web is based on HTTP and is built for efficiency of
HTTP. Things like HTTP caching enable Restful services to be effective.
High Performance : Less xml & soap overhead and More caching enable Restful services to be
highly performant.
All comparison is between the Sample Restful and SOAP implementations described above.
REST is built over simple HTTP protocol. SOAP services are more complex to implement and more
complex to consume.
REST has better performance and scalability. REST reads can be cached, SOAP based reads
cannot be cached.
REST permits many different data formats (JSON is the most popular choice) where as SOAP only
permits XML.