Webservice Interview Question
  1. What is a Web Service?

    A Web Service can be defined as an application component for communication or say exchanging information between two applications over the network. Web services basically work on client server model where web services are easily accessible to client applications over the network.

    Web services provide endpoint URLs and expose methods that can be accessed over network through client programs written in java, shell script or any other different technologies. Web services are stateless and doesn’t maintain user session like web applications.

  2. What are the advantages of Web Services?

    Some of the advantages of web services are:

    • Interoperability: Web services are accessible over network and runs on HTTP/SOAP protocol and uses XML/JSON to transport data, hence it can be developed in any programming language. Web service can be written in java programming and client can be PHP and vice versa.
    • Reusability: One web service can be used by many client applications at the same time.
    • Loose Coupling: Web services client code is totally independent with server code, so we have achieved loose coupling in our application.
    • Easy to deploy and integrate, just like web applications.
    • Multiple service versions can be running at same time.
  3. What are the main features of web services?

    Following is a list of main features of web services:

    • It is available over the Internet or private (intranet) networks.
    • It uses a standardized XML messaging system.
    • It is not tied to any one operating system or programming language.
    • It is self-describing via a common XML grammar.
    • It is discoverable via a simple find mechanism.
  4. What are different types of Web Services?

    There are two types of web services:

    1. SOAP Web Services: Runs on SOAP(Simple Object Access Protocol) protocol and uses XML technology for sending data.
    2. Restful Web Services: It’s an architectural style and runs on HTTP/HTTPS protocol almost all the time. REST is a stateless client-server architecture where web services are resources and can be identified by their URIs. Client applications can use HTTP GET/POST methods to invoke Restful web services.
  5. What is SOAP?

    SOAP stands for Simple Object Access Protocol. SOAP is an XML based industry standard protocol for designing and developing web services. Since it’s XML based, it’s platform and language independent. So our server can be based on JAVA and client can be on .NET, PHP etc. and vice versa.

  6. What are advantages of SOAP Web Services?

    SOAP web services have all the advantages that web services has, some of the additional advantages are:

    • WS Security: SOAP defines its own security known as WS Security.
    • Language and Platform independent: SOAP web services can be written in any programming language and executed in any platform.
  7. What are disadvantages of SOAP Web Services?

    Some of the disadvantages of SOAP protocol are:

    • Only XML can be used, JSON and other lightweight formats are not supported.
    • SOAP is based on the contract, so there is a tight coupling between client and server applications.
    • SOAP is slow because payload is large for a simple string message, since it uses XML format.
    • Anytime there is change in the server side contract, client stub classes need to be generated again.
    • Can’t be tested easily in browser
  8. What is WSDL?

    WSDL stands for Web Service Description Language. WSDL is an XML based document that provides technical details about the web service. Some of the useful information in WSDL document are: method name, port types, service end point, binding, method parameters etc.

  9. What are different components of WSDL?

    Some of the different tags in WSDL xml are:

    • xsd:import namespace and schemaLocation: provides WSDL URL and unique namespace for web service.
    • message: for method arguments
    • part: for method argument name and type
    • portType: service name, there can be multiple services in a wsdl document.
    • operation: contains method name
    • soap:address for endpoint URL.
  10. What is UDDI?

    UDDI is acronym for Universal Description, Discovery and Integration. UDDI is a directory of web services where client applications can lookup for web services. Web Services can register to the UDDI server and make them available to client applications.

  11. What is UDDI?

    In Top Down approach first WSDL document is created to establish the contract between web service and client and then code is written, it’s also termed as contract first approach. This is hard to implement because classes need to be written to confirm the contract established in WSDL. Benefit of this approach is that both client and server code can be written in parallel.

    In Bottom Up approach, first web service code is written and then WSDL is generated. It’s also termed as contract last approach. This approach is easy to implement because WSDL is generated based on code. In this approach client code have to wait for WSDL from server side to start their work.

  12. What is REST Web Services?

    REST is the acronym for REpresentational State Transfer. REST is an architectural style for developing applications that can be accessed over the network.

    REST is a stateless client-server architecture where web services are resources and can be identified by their URIs. Client applications can use HTTP GET/POST methods to invoke Restful web services. REST doesn’t specify any specific protocol to use, but in almost all cases it’s used over HTTP/HTTPS. When compared to SOAP web services, these are lightweight and doesn’t follow any standard. We can use XML, JSON, text or any other type of data for request and response.

  13. What are advantages of REST web services?

    Some of the advantages of REST web services are:

    • Fast: RESTful Web Services are fast because there is no strict specification like SOAP. It consumes less bandwidth and resource.
    • Language and Platform independent: RESTful web services can be written in any programming language and executed in any platform.
    • Can use SOAP: RESTful web services can use SOAP web services as the implementation.
    • Permits different data format: RESTful web service permits different data format such as Plain Text, HTML, XML and JSON.
  14. What are disadvantages of REST web services?

    Some of the disadvantages of REST are:

    • Since there is no contract defined between service and client, it has to be communicated through other means such as documentation or emails.
    • Since it works on HTTP, there can’t be asynchronous calls.
    • Sessions can’t be maintained.
  15. What are different HTTP Methods supported in Restful Web Services?

    Restful web services supported HTTP methods are – GET, POST, PUT, DELETE and HEAD.

  16. What are differences between REST and SOAP web services?

    Refer our article on Difference between REST and SOAP web services

  17. What is the purpose and format of URI in REST architecture?

    Purpose of URI is to locate resources on the server that are hosting web services.

    Format of URI


  18. Explain the term statelessness in terms of RESTful web services?

    In REST architecture, there is a restriction where a REST web service is not allowed to keep a client state on the server. Such condition is known as ‘Statelessness’. In such situation, the client passes its context to the server and in turn, the server stores the context in order to process client’s further requests.

  19. What are different ways to test web services?

    SOAP web services can be tested programmatically by generating client stubs from WSDL or through software such as Soap UI.

    REST web services can be tested easily with program, curl commands and through browser extensions. Resources supporting GET method can be tested with browser itself, without any program.

  20. Can we maintain user session in web services?

    Web services are stateless so we can’t maintain user sessions in web services.

  21. What is JAX-WS API?

    JAX-WS stands for Java API for XML Web Services. JAX-WS is XML based Java API to build web services server and client application. It’s part of standard Java API, so we don’t need to include anything else which working with it.

  22. How to get WSDL file of a SOAP web service?

    WSDL document can be accessed by appending ?wsdl to the SOAP endoint URL. In above example, we can access it at http://localhost:8888/testWS?wsdl location.

  23. What is JAX-RS API?

    Java API for RESTful Web Services (JAX-RS) is the Java API for creating REST web services. JAX-RS uses annotations to simplify the development and deployment of web services. JAX-RS is part of JDK, so you don’t need to include anything to use it’s annotations.

  24. Name some implementations of JAX-RS API?

    There are two major implementations of JAX-RS API.

    • Jersey: Jersey is the reference implementation provided by Sun. For using Jersey as our JAX-RS implementation, all we need to configure its servlet in web.xml and add required dependencies. Note that JAX-RS API is part of JDK not Jersey, so we have to add its dependency jars in our application.
    • RESTEasy: RESTEasy is the JBoss project that provides JAX-RS implementation.
  25. Name important annotations used in JAX-RS API?

    Some of the important JAX-RS annotations are:

    • @Path: used to specify the relative path of class and methods. We can get the URI of a webservice by scanning the Path annotation value.
    • @GET, @PUT, @POST, @DELETE and @HEAD: used to specify the HTTP request type for a method.
    • @Produces, @Consumes: used to specify the request and response types.
    • @PathParam: used to bind the method parameter to path value by parsing it.
  26. What is the use of @XmlRootElement annotation?

    XmlRootElement annotation is used by JAXB to transform java object to XML and vice versa. So we have to annotate model classes with this annotation.

  27. How to set different status code in HTTP response?

    For setting HTTP status code other than 200, we have to use javax.ws.rs.core.Response class for response. Below are some of the sample return statements showing it’s usage.

    return Response.status(422).entity(exception).build(); return Response.ok(response).build(); //200
  28. What is wsimport utility?

    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. This wsimport tool is available in the $JDK/bin folder.

  29. Is binding between SOAP and WSDL possible?

    Yes, it is possible to bind WSDL to SOAP. The binding is possible by basically two attributes

    • Name: Defines the name of the binding.
    • Type: Defines the port for the binding.

    For SOAP binding, two attributes need to be declared

    • Transport: Defines the SOAP protocol to be used i.e. HTTP.
    • Style: This attribute can be ‘rpc’ or ‘document’.
  30. Explain <definition> element?

    Definition element is described as the root of WSDL document which defines the name of the web service as well as act as a container for all the other elements.

Leave a Reply

Your email address will not be published. Required fields are marked *