Documente Academic
Documente Profesional
Documente Cultură
Part - B
Components of Ajax:-
1. Explain the Client-server architecture of Ajax with a neat
diagram. JavaScript
AJAX is a developer's dream, because you can: Loosely typed scripting language.
o Update a web page without reloading the page JavaScript function is called when an event occurs in a page.
o Request data from a server - after the page has loaded Glue for the whole AJAX operation.
o Receive data from a server - after the page has loaded DOM
o Send data to a server - in the background API for accessing and manipulating structured documents.
AJAX is not a programming language. Represents the structure of XML and HTML documents.
AJAX is a technique for accessing web servers from a web page. CSS
AJAX stands for Asynchronous JavaScript And XML. Allows for a clear separation of the presentation style from the
AJAX allows web pages to be updated asynchronously by content and may be changed programmatically by JavaScript.
exchanging data with a web server behind the scenes. XMLHttpRequest
This means that it is possible to update parts of a web page, JavaScript object that performs asynchronous interaction with
without reloading the whole page. the server.
AJAX cannot work independently. It is used in combination with
other technologies to create interactive webpages.
RIA Technology Example for AJAX: Google maps, Gmail, cricket update websites,
stock markets websites, etc
AJAX is the most viable Rich Internet Application (RIA)
technology so far.
It is getting tremendous industry momentum and several tool
Example:-
kit and frameworks are emerging.
<!DOCTYPE html>
But at the same time, AJAX has browser incompatibility and it
<html>
is supported by JavaScript, which is hard to maintain and
<body>
debug.
<div id="demo">
<h1>The XMLHttpRequest Object</h1>
<button type="button" onclick="loadDoc()">Change Content</button>
</div>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200)
{
document.getElementById("demo").innerHTML =
this.responseText;
}
};
xhttp.open("GET", "ajax_info.txt", true);
xhttp.send();
}
</script>
</body>
</html>
XMLHttpRequest Properties
onreadystatechange : An event handler for an event that fires
at every state change.
Server side:- readyState : The readyState property defines the current state
of the XMLHttpRequest object.
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.
readyState = 0 After you have created the
XMLHttpRequest object, but before you have called the
open() method
Client side:- readyState = 1 After you have called the open() method,
but before you have called send().
readyState = 2 After you have called send().
readyState = 3 After the browser has established a
communication with the server, but before the server has
completed the response.
readyState = 4 After the request has been completed,
and the response data has been completely received
from the server.
responseText :Returns the response as a string.
responseXML :Returns the response as XML.
status : Returns the status as a number (e.g., 404 for "Not
Found" and 200 for "OK").
statusText :Returns the status as a string (e.g., "Not Found"
or "OK").
} <portType>
}; <operation>
xhttp.open("GET", "xmlhttp_info.txt", true); definition of a operation.......
xhttp.send(); </operation>
} </portType>
</script>
<binding>
</body>
definition of a binding....
</html> </binding>
O/p:-
<service>
definition of a service....
</service>
</definitions>
<definitions name="HelloService"
The onreadystatechange property specifies a function to be
targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl"
executed every time the status of the XMLHttpRequest object
changes. xmlns="http://schemas.xmlsoap.org/wsdl/"
When readyState property is 4 and the status property is 200, the xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
response is ready. xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl"
responseText property returns the server response as a text string. xmlns:xsd="http://www.w3.org/2001/XMLSchema">
The text string can be used to update a web page
<message name="SayHelloRequest">
3. Describe WSDL with diagrams necessary. <part name="firstName" type="xsd:string"/>
WSDL stands for Web Services Description Language </message>
WSDL is used to describe web services
WSDL is written in XML <message name="SayHelloResponse">
WSDL is a W3C recommendation from 26. June 2007 <part name="greeting" type="xsd:string"/>
It is the standard format for describing a web service. </message>
WSDL was developed jointly by Microsoft and IBM.
<portType name="Hello_PortType">
Features of WSDL
<operation name="sayHello">
WSDL is an XML-based protocol for information exchange in
<input message="tns:SayHelloRequest"/>
decentralized and distributed environments.
<output message="tns:SayHelloResponse"/>
WSDL definitions describe how to access a web service and </operation>
what operations it will perform. </portType>
WSDL is a language for describing how to interface with XML- <binding name="Hello_Binding" type="tns:Hello_PortType">
based services. <soap:binding style="rpc"
WSDL is an integral part of Universal Description, Discovery, transport="http://schemas.xmlsoap.org/soap/http"/>
and Integration (UDDI), an XML-based worldwide business <operation name="sayHello">
registry. <soap:operation soapAction="sayHello"/>
WSDL is the language that UDDI uses. <input>
WSDL is pronounced as 'wiz-dull' and spelled out as 'W-S-D-L'. <soap:body
WSDL Elements encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
Types a container for data type definitions using some type namespace="urn:examples:helloservice"
system (such as XSD). use="encoded"/>
Message an abstract, typed definition of data being communicated. </input>
Operation an abstract description of an action supported by service. <output>
Port Typean abstract set of operations supported by one or more <soap:body
endpoints.
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
Binding a concrete protocol and data format specification for a particular
port type.
namespace="urn:examples:helloservice"
Port a single endpoint defined as a combination of a binding and a use="encoded"/>
network address. </output>
Service a collection of related endpoints. </operation>
</binding>
<service name="Hello_Service"> IN
<documentation>WSDL File for HelloService</documentation> Why SOAP?
<port binding="tns:Hello_Binding" name="Hello_Port"> It is important for web applications to be able to communicate
<soap:address over the Internet.
location="http://www.examples.com/SayHello/" /> The best way to communicate between applications is over
</port> HTTP, because HTTP is supported by all Internet browsers
</service> and servers. SOAP was created to accomplish this.
</definitions> SOAP provides a way to communicate between applications
running on different operating systems, with different
Example Analysis technologies and programming languages.
Definitions : HelloService SOAP Building Blocks
Type : Using built-in data types and they are defined in An Envelope element that identifies the XML document as a
XMLSchema. SOAP message
Message : A Header element that contains header information
o sayHelloRequest : firstName parameter A Body element that contains call and response information
o sayHelloresponse: greeting return value A Fault element containing errors and status information
Port Type : sayHello operation that consists of a request and
a response service. Syntax Rules
Binding : Direction to use the SOAP HTTP transport protocol. A SOAP message MUST be encoded using XML
Service : Service available at A SOAP message MUST use the SOAP Envelope namespace
http://www.examples.com/SayHello/ A SOAP message MUST use the SOAP Encoding namespace
Port : Associates the binding with the URI A SOAP message must NOT contain a DTD reference
http://www.examples.com/SayHello/ where the running service A SOAP message must NOT contain XML Processing
can be accessed. Instructions
o <?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-
envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soa
p-encoding">
<soap:Header>
...
</soap:Header>
<soap:Body>
...
<soap:Fault>
...
</soap:Fault>
</soap:Body>
</soap:Envelope>
4. Explain the working of SOAP with an example.
SOAP request
SOAP stands for Simple Object Access Protocol
SOAP is an application communication protocol POST /Quotation HTTP/1.0
SOAP is a format for sending and receiving messages Host: www.xyz.org
SOAP is platform independent Content-Type: text/xml; charset=utf-8
SOAP is based on XML Content-Length: nnn
SOAP is a W3C recommendation
SOAP 1.1 was originally submitted to the W3C in May 2000. <?xml version="1.0"?>
Official submitters included large companies such as <SOAP-ENV:Envelope xmlns:SOAP-
Microsoft, IBM, and Ariba, and smaller companies such as ENV="http://www.w3.org/2001/12/soap-envelope" SOAP-
UserLand Software and DevelopMentor. ENV:encodingStyle="http://www.w3.org/2001/12/soap-encoding" >
<SOAP-ENV:Body xmlns:m="http://www.xyz.org/quotations" >
<m:GetQuotation>
<m:QuotationsName>MiscroSoft</m:QuotationsName>
</m:GetQuotation>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
HTTP/1.0 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: nnn
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-
ENV="http://www.w3.org/2001/12/soap-envelope" SOAP-
ENV:encodingStyle="http://www.w3.org/2001/12/soap-
encoding" >
<SOAP-ENV:Body xmlns:m="http://www.xyz.org/quotation"
>
<m:GetQuotationResponse>
<m:Quotation>Here is the quotation</m:Quotation>
</m:GetQuotationResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>