Q5) Write a short note on any two of the following. [2×3=6]
1. Web services communication models.
Web services are of two kinds: Simple
Object Access Protocol (SOAP) and Representational State Transfer (REST). SOAP defines a standard communication protocol (set of
rules) specification for XML-based message exchange. SOAP uses different
transport protocols, such as HTTP and SMTP
XML Soap
- SOAP
stands for Simple Object Access Protocol
- SOAP is
an application communication protocol
- SOAP is
a format for sending and receiving messages
- SOAP is
platform independent
- SOAP is based on XML,
- SOAP is a W3C recommendation
A SOAP message is an ordinary XML document
containing the following elements:
- An
Envelope element that identifies the XML document as a SOAP message
- A
Header element that contains header information
- A Body
element that contains call and response information
- A Fault
element containing errors and status information
REST (Representational State Transfer) is a system architecture that defines the set of methods to access the web services. The main goal of REST API is to create a system that can be used by different applications. The REST API are created with CRUD (Create, Read, Update, Delete) operations.
2. Sticky Forms.
A “sticky” form is one where, when you re-visit the form, your previous information is already filled in.
Example:-
<html>
<body>
<?php
$fahr=$_POST['fahrenheit']
<form action="<?php echo $_SERVER['PHP_SELF']?>"method="POST">
fahrenheit temperature:
<input type="text" name="fahrenheit" value=if(isset(=$_POST['fahrenheit'])){echo $fahr}?>>
<input type ="submit">
</form>
<?php
$Celsius=($fahr-32)*5/9;
printf("%f:%f,$fahr,$Celsius);
?>
</body>
</html>
3.Encapsulation.
- Encapsulation is a concept where we
encapsulate all the data and member functions together to
form an object.
- Wrapping up data member and method
together into a single unit is called Encapsulation.
- Encapsulation also allows a class
to change its internal implementation without hurting the overall
functioning of the system.
- Binding the data with the code that manipulates
it.
- It keeps the data and the code safe
from external interference.
4.WSDL.
- WSDL
stands for Web Services Description Language
- WSDL is
used to describe web services
- WSDL is
written in XML
Features of WSDL
· WSDL is an XML-based protocol for information exchange in decentralized
and distributed environments.
· WSDL definitions describe how to access a web service and what
operations it will perform.
· WSDL is a language for describing how to interface with XML-based
services.
· WSDL is an integral part of Universal Description, Discovery, and
Integration (UDDI), an XML-based worldwide business registry.
·
WSDL is the language that UDDI uses.
·
WSDL is pronounced as 'wiz-dull' and spelled out as 'W-S-D-L
5.XML parser.
An XML parser is a
software library or package that provides interfaces for client applications to
work with an XML document. The XML Parser is designed to read the XML and
create a way for programs to use XML.
Types
of XML Parsers
1. DOM
2. SAX
DOM (Document Object Model)
A DOM
document is an object which contains all the information of an XML document. It
is composed like a tree structure. The DOM Parser implements a DOM API. This
API is very simple to use.
Features of DOM Parser
A DOM
Parser creates an internal structure in memory which is a DOM document object
and the client applications get information of the original XML document by invoking
methods on this document object.
DOM Parser
has a tree based structure.
Advantages
1) It
supports both read and write operations and the API is very simple to use.
2) It is
preferred when random access to widely separated parts of a document is required.
Disadvantages
1) It is
memory inefficient. (consumes more memory because the whole XML document needs
to loaded into memory).
2) It is
comparatively slower than other parsers.
SAX
(Simple API for XML)
A SAX Parser implements SAX API. This API is an event
based API and less intuitive.
Features
of SAX Parser
It does not create any internal structure.
Clients does not know what methods to call, they just
overrides the methods of the API and place his own code inside method.
It is an event based parser, it works like an event
handler in Java.
Advantages
1) It is simple and memory efficient.
2) It is very fast and works for huge documents.
Disadvantages
1) It is
event-based so its API is less intuitive.
2) Clients
never know the full information because the data is broken into pieces.
6.XMLHTTP Request object.
An object
of XMLHttpRequest is used for asynchronous communication between client and
server.
It performs following operations:
Sends data
from the client in the background
Receives
the data from the server
Updates the
webpage without reloading it.
XMLHttpRequest Properties
1.onreadystatechange
An event handler for an event that fires at every state change.
2.readyState
The readyState property defines the current state of the XMLHttpRequest
object.
The following table provides a list of the possible values for the
readyState property
State |
Description |
0 |
The request is not initialized. |
1 |
The request has been set up. |
2 |
The request has been sent. |
3 |
The request is in process. |
4 |
The request is completed. |
7. header()
function
The PHP header() function does not return any
value.
Uses
- It changes the page
location.
- It sets the time
zone.
- It sends the STOP
status.
- This function sets
the caching control.
- It initiates the
force download.
<?php
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
?>
8. DESTRUCTOR
- PHP 5 introduces a destructor concept similar to that of
other object-oriented languages, such as C++.
- The destructor method will be called as soon as all references
to a particular object are removed or when the object is explicitly
destroyed in any order in shutdown sequence.
- We create destructor by using "__destruct"
function.
<?php
class demo
{
public function demo()
{
echo "constructor1...";
}
}
class demo1 extends demo
{
public function __construct()
{
echo parent::demo();
echo "constructor2...";
}
public function __destruct()
{
echo "destroy.....";
}
}
$obj= new demo1();
?>
9.CONSTRUCTOR
PHP 5
allows developers to declare constructor methods for classes.
Constructor
is suitable for any initialization that the object may need before it
is used.
We
can design constructor using "__construct" or same name as
class name.
Parent
constructors are not called implicitly if the child class defines a
constructor. In order to run a parent constructor, a call to parent::__construct().
<?php
class Example
{
public function __construct()
{
echo "Hello";
}
}
$obj = new Example();
$obj = new Example();
?>
10.How AJAX works?
AJAX
communicates with the server using XMLHttpRequest object. Let's try to
understand the flow of ajax or how ajax works by the image displayed below.
1. User
sends a request from the UI and a javascript call goes to XMLHttpRequest
object.
2. HTTP
Request is sent to the server by XMLHttpRequest object.
3. Server
interacts with the database using JSP, PHP, Servlet, ASP.net etc.
4. Data
is retrieved.
5. Server
sends XML data or JSON data to the XMLHttpRequest callback function.
6. HTML
and CSS data is displayed on the browser.
.