Web Services and Middleware 2.1 Web Services and Middleware
Web Services and Middleware 2.1 Web Services and Middleware
Chapter 2
Web Services and Middleware; Network programming; Message
and queuing services; Low level data communications
2.1 Web Services and Middleware
Web services:
Web Services is an application integration technology.
Web Services allow applications to be integrated more rapidly,
easily and less expensively. The Web did for program-to-user
interactions; Web Services are developed for program-to-
program interactions. Web Services allow companies to reduce
the cost of doing e-business, to deploy solutions faster and
to open up new opportunities. Web services model built on
existing and emerging standards such as HTTP, Extensible
Markup Language (XML), Simple Object Access Protocol (SOAP),
Web Services Description Language (WSDL) and Universal
Description, Discovery and Integration (UDDI).
XML Web Services expose useful functionality to Web users
through a standard Web protocol. In most cases, the protocol
used is SOAP.
XML Web services provide a way to describe their interfaces
in enough detail to allow a user to build a client
application to talk to them. This description is usually
provided in an XML document called a Web Services
Description Language (WSDL) document.
XML Web services are registered so that potential users can
find them easily. This is done with Universal Discovery
Description and Integration (UDDI).
Web service is developed in order to distribute an object
and serve it to various users in the web environments. It can
be also used in the server situations while solving the web-
scalability problem of the other distributed object
technologies. Fig.2.1 demonstrates the web service
architecture.
1 ||By:Beya
Integrative programming and technologies
2 ||By:Beya
Integrative programming and technologies
3 ||By:Beya
Integrative programming and technologies
Client/Server Computing
You can use the Java language to communicate with remote file
systems using aclient/server model. A server listens for
connection requests from clients acrossthe network or even
from the same machine. Clients know how to connect to
theserver via an IP address and port number. Upon connection,
the server reads therequest sent by the client and responds
appropriately. In this way, applicationscan be broken down
into specific tasks that are accomplished in
separatelocations.
The data that is sent back and forth over a socket can be
anything you like.Normally, the client sends a request for
information or processing to the server,which performs a task
or sends data back. The IP and port number of the server is
generally well-known and advertised sothe client knows where
to find the service.
How UDPclients and UDPservers communicate over sockets
Creating UDP Servers:
To create a server with UDP, do the following:
1. Create a DatagramSocket attached to a port.
int port = 1234;
DatagramSocket socket = new DatagramSocket(port);
2. Allocate space to hold the incoming packet, and create an
instance ofDatagramPacket to hold the incoming data.
byte[] buffer = new byte[1024];
DatagramPacket packet =new DatagramPacket(buffer,
buffer.length);
3. Block until a packet is received, then extract the
information you need from thepacket.
4 ||By:Beya
Integrative programming and technologies
// Block on receive()
socket.receive(packet);
// Find out where packet came from
// so we can reply to the same host/port
InetAddressremoteHost = packet.getAddress();
intremotePort = packet.getPort();
// Extract the packet data
byte[] data = packet.getData();
The server can now process the data it has received from the
client, and issue anappropriate reply in response to the
client's request.
Creating UDP Clients
Writing code for a UDP client is similar to what we did for a
server. Again, weneed a DatagramSocket and a DatagramPacket.
The only real difference is thatwe must specify the
destination address with each packet, so the form of
theDatagramPacket constructor used here specifies the
destination host and portnumber. Then, of course, we initially
send packets instead of receiving.
1. First allocate space to hold the data we are sending and
create an instance ofDatagramPacket to hold the data.
byte[] buffer = new byte[1024];
int port = 1234;
InetAddress host =InetAddress.getByName("magelang.com");
DatagramPacket packet =new DatagramPacket(buffer,
buffer.length,host, port);
2. Create a DatagramSocket and send the packet using this
socket.
DatagramSocket socket = new DatagramSocket();
socket.send(packet);
The DatagramSocket constructor that takes no arguments will
allocate a free localport to use. You can find out what local
port number has been allocated for yoursocket, along with
other information about your socket if needed.
// Find out where we are sending from
InetAddresslocalHostname = socket.getLocalAddress();
intlocalPort = socket.getLocalPort();
The client then waits for a reply from the server. Many
protocols require theserver to reply to the host and port
number that the client used, so the client cannow invoke
socket.receive() to wait for information from the server.
How TCPclients and TCPservers communicate over sockets
Creating TCP Servers:
To create a TCP server, do the following:
5 ||By:Beya
Integrative programming and technologies
6 ||By:Beya
Integrative programming and technologies
7 ||By:Beya
Integrative programming and technologies
8 ||By:Beya
Integrative programming and technologies
9 ||By:Beya