You are on page 1of 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 se
rvice 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 kind
of operating system (such as Windows 2000) to communicate with a progam in the s
ame or another kind of an operating system (such as Linux) by using the World Wi
de Web's Hypertext Transfer Protocol (HTTP)and its Extensible Markup Language (X
ML) as the mechanisms for information exchange. Since Web protocols are installe
d and available for use by all major operating system platforms, HTTP and XML pr
ovide an already at-hand solution to the problem of how programs running under d
ifferent operating systems in a network can communicate with each other. SOAP sp
ecifies exactly how to encode an HTTP header and an XML file so that a program i
n one computer can call a program in another computer and pass it information. I
t also specifies how the called program can return a response.
What are Resful Web services?
REST is a client-server architecture which
use 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 it
provides a mechanism for services to describe themselves to clients, and to adve
rtise their existence.
REST is much more lightweight and can be implemented using almost any tool, lead
ing to lower bandwidth and shorter learning curve.
However, the clients have to know what to send and what to expect.In general, Wh
en you're publishing an API to the outside world that is either complex or likel
y to change, SOAP will be more useful. Other than that, REST is usually the bett
er 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 SOA
P is XML which is text, so as long as the language has an XML parser to marshal
and 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 built
in parser, you can write the parser code yourself if you are game. All it needs
is 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 been
compiled 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 WSDL
WSDL stands for Web Services Description Language.
WSDL is a document written in XML. The document describes a Web service. It spec
ifies the location of the service
and 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

executing the next statement.


Asynchronous Web service call : A program calling the web service
t to the web service and proceeds with the execution of remaining
n before the web service has returned any response. (This may be
service might take time to compute and generate the response, and
sn t want to wait till it receives the response)

sends a reques
statements eve
because a web
the client doe

Example of how to make asynchronous calls to JAX-WS Web service


1) Create a sample JAX-WS Web service and publish it
19
@WebService
public 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 SimpleSOAPSe
rviceImpl());
}
}
2) Create a binding xml to be used with wsimport
<!--?xml version="1.0" encoding="UTF-8" standalone="yes"?-->
<!-- Applies to all the methods in the wsdl. If set to true all the meth
ods can be
invoked asynchronously -->
<enableAsyncMapping>true</enableAsyncMapping>
<!-- Applies asynchronous binding only to selected methods -->
<!-- Uncomment below binding section, when the above 'enableAsyncMapping
' tag
is set to false -->
<!-<bindings node="wsdl:definitions/wsdl:portType[@name='SimpleSOAPServiceI
mpl']/wsdl:operation[@name='sayHello']">
<enableAsyncMapping>true</enableAsyncMapping>
</bindings>
-->
3) Run wsimport to generate client artifacts. (I ran from command prompt)
1
D:/> wsimport http://localhost:1234/MySOAPService?wsdl -b asyncBinding.x
ml -s .
4) Check the generated interface after running wsimport. This will have 2 extra
methods(sayHelloAsync) for each method which was specified in the binding file
15
16
// Asynchronous Method
public Response sayHelloAsync(
@WebParam(name = "echo", targetNamespace = "")
String echo);
// Asynchronous Method

public Future<?> sayHelloAsync(


@WebParam(name = "echo", targetNamespace = "")
String echo,
@WebParam(name = "asyncHandler", targetNamespace = "")
AsyncHandler asyncHandler);
// Synchronous Method
public 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.. e
ven 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 magic
happens at the client side.
How do you handle errors in Web Service call
Using Java Exceptions.& SOA Exception.
What is WebServiceTemplate
The 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 messages
as either Source or Result.
Additionally, it can marshal objects to XML before sending them across a transpo
rt, and unmarshal any response XML into an object again.
Differences between Jax-ws and Jax-RPC
JAX-WS allows for asynchronous communication as opposed to procedural blocking r
esponses. Also the serialization and
deserialization of XML data is done more efficiently and faster using the latest
JAXB 2.0 implementation which is
much 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 fo
r creating web services.
JAX-WS is one of the Java XML programming APIs. It is part of the Java EE platfo
rm from Sun Microsystems
The JAX-WS 2.2 specification JSR 224 defines a standard Java- to-WSDL mapping wh
ich determines how WSDL operations are bound to Java methods
when a SOAP message invokes a WSDL operation. This Java-to-WSDL mapping determi

nes which Java method gets invoked and how that SOAP message is
mapped to the method s parameters.This mapping also determines how the method s retu
rn value gets mapped to the SOAP response.
what is jaxb?
Java Architecture for XML Binding (JAXB) allows Java developers to map Java clas
ses to XML representations. JAXB provides two main features: the ability to mars
hal Java objects into XML and the inverse, i.e. to unmarshal XML back into Java
objects. In other words, JAXB allows storing and retrieving data in memory in an
y XML format, without the need to implement a specific set of XML loading and sa
ving routines for the program's class structure.
JAXB is particularly useful when the specification is complex and changing. In s
uch a case, regularly changing the XML Schema definitions to keep them synchroni
sed with the Java definitions can be time consuming and error-prone.

You might also like