Sunteți pe pagina 1din 6

CS6501 INTERNET PROGRAMMING

IN7. What are the components of Web Services?


UNIT 5 - AJAX & WEB SERVICES The basic web services platform is XML + HTTP.
Part-A SOAP (Simple Object Access Protocol)
1. What is Ajax? UDDI (Universal Description, Discovery and Integration)
AJAX is an acronym for asynchronous JavaScript and XML WSDL (Web Services Description Language)
It is a set of web development techniques using many web 8. What are the advantages of web service?
technologies on the client-side to create asynchronous Web Exposing the Existing Function on the network
applications. Interoperability
With Ajax, web applications can send data to and retrieve from Standardized protocol
a server asynchronously (in the background) without Low Cost of Communication
interfering with the display and behavior of the existing page. 9. What are RESTful web services?
Ajax is not a technology, but a group of technologies. RESTful Web Services are REST architecture based web
HTML and CSS can be used in combination to mark up and services.
style information. In REST Architecture everything is a resource. RESTful web
The DOM is accessed with JavaScript to dynamically display services are light weight, highly scalable and maintainable
and allow the user to interact with the information presented. It is very commonly used to create APIs for web based
JavaScript and the XMLHttpRequest object provide a applications.
method for exchanging data asynchronously between REST stands for REpresentational State Transfer.
browser and server to avoid full page reloads. REST is web standards based architecture and uses HTTP
2. Mention the open standards of Ajax. Protocol for data communication.
Browser-based presentation using HTML and Cascading Style 10. Define WSDL
Sheets (CSS). WSDL stands for Web Services Description Language.
Data is stored in XML format and fetched from the server. It is the standard format for describing a web service.
Behind-the-scenes data fetches using XMLHttpRequest WSDL was developed jointly by Microsoft and IBM.
objects in the browser. To exchange information in a distributed environment.
JavaScript to make everything happen. WSDL is used to describe web services
3. Brief about asynchronous nature of AJAX. WSDL is written in XML
Asynchronous means that the script will send a request to the WSDL is a W3C recommendation from 26. June 2007
server, & continue it's execution without waiting for reply. 11. What are the elements of WSDL?
As soon as reply is received a browser event is fired, which in Types a container for data type definitions using some type
turn allows the script to execute associated actions. system (such as XSD).
Ajax knows when to pull data from server, because you tell it Message an abstract, typed definition of the data being
when to do it. communicated.
4. What is XHR? Operation an abstract description of an action supported by
XMLHttpRequest (XHR) is an API that can be used by the service.
JavaScript, JScript, VBScript, and other web browser scripting Port Typean abstract set of operations supported by one or
languages to transfer and manipulate XML data to and from a more endpoints.
webserver using HTTP, establishing an independent Binding a concrete protocol and data format specification for
connection channel between a webpage's Client-Side and a particular port type.
Server-Side. Port a single endpoint defined as a combination of a binding
Update a web page without reloading the page and a network address.
Request data from a server - after the page has Service a collection of related endpoints.
loaded 12. Define SOAP
Receive data from a server - after the page has SOAP is an acronym for Simple Object Access Protocol.
loaded It is an XML-based messaging protocol for exchanging
Send data to a server - in the background information among computers.
5. What is a web service?
SOAP is an application of the XML specification.
Web services are open standard (XML, SOAP, HTTP etc.)
SOAP is an application communication protocol
based Web applications that interact with other web
SOAP is a format for sending and receiving messages
applications for the purpose of exchanging data.
It is OS and language independent SOAP is platform independent
Web Services can convert your existing applications into Web- SOAP is based on XML
applications. SOAP is a W3C recommendation
A web service is a collection of open protocols and standards 13. Mention the features of SOAP.
used for exchanging data between applications or systems. SOAP is a communication protocol designed to communicate
via Internet.
6. Mention the characteristics of web service. SOAP can extend HTTP for XML messaging.
SOAP provides data transport for Web services.
SOAP can exchange complete documents or call a remote
Machine-to-machine interactions
procedure.
Loose coupling
Interoperability SOAP can be used for broadcasting a message.
Platform-independence SOAP is platform- and language-independent.
Operating system-independence SOAP is the XML way of defining what information is sent and
Language-independence how.
Leveraging the architecture of the World Wide Web SOAP enables client applications to easily connect to remote
services and invoke remote methods.

PREPARED BY V.BALAMURUGAN, ASST.PROF/CSE


CS6501 INTERNET PROGRAMMING

14. List out the elements of SOAP INSteps of Processing in Ajax:-


An Envelope element that identifies the XML document as a 1. An event occurs in a web page (the page is loaded, a button is
SOAP message clicked)
A Header element that contains header information 2. An XMLHttpRequest object is created by JavaScript
A Body element that contains call and response information 3. The XMLHttpRequest object sends a request to a web server
A Fault element containing errors and status information 4. The server processes the request
15. Mention the advantages of SOAP. 5. The server sends a response back to the web page
Simplicity Universal acceptance 6. The response is read by JavaScript
Portability Versatile 7. Proper action (like page update) is performed by JavaScript
Firewall flexible
AJAX is based on the following open standards:-
Scalable Interoperability
Browser-based presentation using HTML and Cascading Style
Friendliness No bi-directional HTTP Sheets (CSS).
communication Data is stored in XML format and fetched from the server.
Use of open standards No distributed garbage Behind-the-scenes data fetches using XMLHttpRequest
collection objects in the browser.
No Object activation. No Object by reference. JavaScript to make everything happen.

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>

PREPARED BY V.BALAMURUGAN, ASST.PROF/CSE


CS6501 INTERNET PROGRAMMING

O/P:- INXMLHttpRequest Methods


abort() : Cancels the current request.
getAllResponseHeaders() : Returns the complete set of
HTTP headers as a string.
getResponseHeader( headerName ) : Returns the value of
the specified HTTP header.
open( method, URL )

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").

2. Explain XMLHttpRequest object with example.

The XMLHttpRequest object can be used to request data from


a web server.
The XMLHttpRequest object is a developers dream, because
you can:
Update a web page without reloading the page
Request data from a server - after the page has loaded
Receive data from a server - after the page has loaded
Send data to a server - in the background
The XMLHttpRequest object is the key to AJAX. It has been
available ever since Internet Explorer 5.5 was released in July Example:-
2000, but was not fully discovered until AJAX and Web 2.0 in <!DOCTYPE html>
2005 became popular. <html>
XMLHttpRequest (XHR) is an API that can be used by <body>
JavaScript, JScript, VBScript, and other web browser scripting <h2>Using the XMLHttpRequest Object</h2>
languages to transfer and manipulate XML data to and from a <div id="demo">
webserver using HTTP, establishing an independent <button type="button"
connection channel between a webpage's Client-Side and onclick="loadXMLDoc()">Change Content</button>
Server-Side. </div>
The data returned from XMLHttpRequest calls will often be <script>
provided by back-end databases. Besides XML,
XMLHttpRequest can be used to fetch data in other formats,
e.g. JSON or even plain text.

PREPARED BY V.BALAMURUGAN, ASST.PROF/CSE


CS6501 INTERNET PROGRAMMING

function loadXMLDoc() INThe WSDL Document Structure


{ <definitions>
var xhttp = new XMLHttpRequest(); <types>
xhttp.onreadystatechange = function() definition of types........
</types>
{
if (this.readyState == 4 && this.status == 200)
<message>
{ definition of a message....
document.getElementById("demo").innerHTML = this.responseText; </message>

} <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>

Contents of HelloService.wsdl file:

<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>

PREPARED BY V.BALAMURUGAN, ASST.PROF/CSE


CS6501 INTERNET PROGRAMMING

<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>

PREPARED BY V.BALAMURUGAN, ASST.PROF/CSE


CS6501 INTERNET PROGRAMMING
IN
SOAP response

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>

PREPARED BY V.BALAMURUGAN, ASST.PROF/CSE

S-ar putea să vă placă și