webservices interview questions

Upload: sarma-kompalli

Post on 02-Jun-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 Webservices Interview Questions

    1/4

    What is a web service?A Web Service is a method of communication between two electronic devices over a network.It is a software function provided at a network address over the web with the service always on as in the concept of utility computing

    What is SOAP ?

    SOAP (Simple Object Access Protocol) is a way for a program running in one kindof operating system (such as Windows 2000) to communicate with a progam in the same or another kind of an operating system (such as Linux) by using the World Wide Web's Hypertext Transfer Protocol (HTTP)and its Extensible Markup Language (XML) as the mechanisms for information exchange. Since Web protocols are installed and available for use by all major operating system platforms, HTTP and XML provide an already at-hand solution to the problem of how programs running under different operating systems in a network can communicate with each other. SOAP specifies exactly how to encode an HTTP header and an XML file so that a program in one computer can call a program in another computer and pass it information. It also specifies how the called program can return a response.

    What are Resful Web services?REST is a client-server architecture whichuse HTTP methods explicitly by mapping the REST operations to HTTP methods:Create POST, Retrieve GET, Update PUT, Delete DELETE

    What is difference between REST Web Service and SOAP web service ?REST is almost always going to be faster. The main advantage of SOAP is that itprovides a mechanism for services to describe themselves to clients, and to advertise their existence.REST is much more lightweight and can be implemented using almost any tool, leading to lower bandwidth and shorter learning curve.However, the clients have to know what to send and what to expect.In general, When you're publishing an API to the outside world that is either complex or likely to change, SOAP will be more useful. Other than that, REST is usually the better option.

    Can a Java client can talk to C++ Server using Web Service?

    SOAP is an industry standard for ALL languages. The document being sent with SOAP is XML which is text, so as long as the language has an XML parser to marshaland unmarshal the XML it will work. Java is well equipped as far as this goes.In fact, if it is an kind of a programming language you don't even need a builtin parser, you can write the parser code yourself if you are game. All it needsis the ability to read a file stream and the ability to access a network socket.So yes, a Java client can talk to a web service running on a host that has beencompiled with C# or C++ or C or whatever. As long as it is a standards based web service.Java, can also communicate with C/C++ through native calls(via the 'native' Java libary), and can also talk to C/C++ using CORBA.There are all kinds of options for Java and C/C++ to talk to each other.

    What is WSDLWSDL stands for Web Services Description Language.WSDL is a document written in XML. The document describes a Web service. It specifies the location of the serviceand the operations (or methods) the service exposes.

    Does Web Service call is synchronous or asynchronous ?We can make both synchronous and asynchronous calls using web services.Synchronous Web service call : A program calling the web service sends a request to the web service and waits till the web service returns the response, before

  • 8/10/2019 Webservices Interview Questions

    2/4

    executing the next statement.Asynchronous Web service call : A program calling the web service sends a request to the web service and proceeds with the execution of remaining statements even before the web service has returned any response. (This may be because a webservice might take time to compute and generate the response, and the client doesn t want to wait till it receives the response)

    Example of how to make asynchronous calls to JAX-WS Web service1) Create a sample JAX-WS Web service and publish it

    19 @WebServicepublic class SimpleSOAPServiceImpl{

    @WebMethod public String sayHello(@WebParam(name = "echo") String echo) { try { Thread.sleep(1000*60*5); // Sleep for 5 minutes return "Hello "+echo; } catch(InterruptedException ex) { // Exception Handling code here.. } return null; }

    public static void main(String args[]) { Endpoint.publish("http://localhost:1234/MySOAPService", new SimpleSOAPServiceImpl()); }}2) Create a binding xml to be used with wsimport

    true

    3) Run wsimport to generate client artifacts. (I ran from command prompt)1 D:/> wsimport http://localhost:1234/MySOAPService?wsdl -b asyncBinding.xml -s .

    4) Check the generated interface after running wsimport. This will have 2 extramethods(sayHelloAsync) for each method which was specified in the binding file

    1516 // Asynchronous Methodpublic Response sayHelloAsync( @WebParam(name = "echo", targetNamespace = "") String echo); // Asynchronous Method

  • 8/10/2019 Webservices Interview Questions

    3/4

    public Future sayHelloAsync( @WebParam(name = "echo", targetNamespace = "") String echo, @WebParam(name = "asyncHandler", targetNamespace = "") AsyncHandler asyncHandler); // Synchronous Methodpublic String sayHello( @WebParam(name = "echo", targetNamespace = "") String echo);5) Invoke the web service from client

    public class Client { public static void main(String args[]) throws Exception { SimpleSOAPServiceImplService service = new SimpleSOAPServiceImplService(); SimpleSOAPServiceImpl port = service.getSimpleSOAPServiceImplPort();

    port.sayHelloAsync("This is Asynchrous call.. "); // port.sayHello("This is synchronous call");

    System.out.println("Execute this statement before async call is complete.. ");

    }}The above client prints Execute this statement before async call is complete.. even before the web service actually finishes processing.

    The beauty of making asynchronous calls from JAX-WS is that the web service need not be modified to support any asynchronous calls and remains as is. All magichappens at the client side.How do you handle errors in Web Service callUsing Java Exceptions.& SOA Exception.

    What is WebServiceTemplateThe WebServiceTemplate is the core class for client-side Web service access in S

    pring-WS.It contains methods for sending Source objects, and receiving response messagesas either Source or Result.Additionally, it can marshal objects to XML before sending them across a transport, and unmarshal any response XML into an object again.Differences between Jax-ws and Jax-RPCJAX-WS allows for asynchronous communication as opposed to procedural blocking responses. Also the serialization anddeserialization of XML data is done more efficiently and faster using the latest JAXB 2.0 implementation which ismuch more performing than the its predecessors.JAX-WS is multi protocol compatible i.e. support of SOAP 1.1 and 1.2.JAX-WS makes heavy of Java annotations as described by the JSR-181 specification

    which simplifies client implementation and readability

    what is jax-ws?The Java API for XML Web Services (JAX-WS) is a Java programming language API for creating web services.JAX-WS is one of the Java XML programming APIs. It is part of the Java EE platform from Sun MicrosystemsThe JAX-WS 2.2 specification JSR 224 defines a standard Java- to-WSDL mapping which determines how WSDL operations are bound to Java methods when a SOAP message invokes a WSDL operation. This Java-to-WSDL mapping determi

  • 8/10/2019 Webservices Interview Questions

    4/4

    nes which Java method gets invoked and how that SOAP message ismapped to the method s parameters.This mapping also determines how the method s return value gets mapped to the SOAP response.

    what is jaxb?Java Architecture for XML Binding (JAXB) allows Java developers to map Java classes to XML representations. JAXB provides two main features: the ability to marshal Java objects into XML and the inverse, i.e. to unmarshal XML back into Javaobjects. In other words, JAXB allows storing and retrieving data in memory in any XML format, without the need to implement a specific set of XML loading and saving routines for the program's class structure.JAXB is particularly useful when the specification is complex and changing. In such a case, regularly changing the XML Schema definitions to keep them synchronised with the Java definitions can be time consuming and error-prone.