WT (U5)
WT (U5)
UNIT-V
Web Services: Introduction to Web Services, UDDI, SOAP, WSDL, Web Service
Architecture, Developing and deploying web services. Ajax – Improving web page
performance using Ajax, Programming in Ajax.
1. What are Web Services? Mention any one supporting language of it? (NOV 2016)
Web services are application components
Web services communicate using open protocols
Web services are self-contained and self-describing
Web services can be discovered using UDDI
Web services can be used by other applications
XML is the basis for Web services
5. What are the advantages and disadvantages of web services? (APR 2016)
Advantages
Reusable application-components
There are things applications needs very often. So why make these over and over again.
Web services can offer application-components like: currency conversion, weather reports, or
even language translation as services.
Connect existing software
Web services can help to solve the interoperability problem by giving different applications a
way to link their data.
With Web services you can exchange data between different applications and different
platforms.
Disadvantages
Web services standards features such as transactions are currently nonexistent or still in their
infancy compared to more mature distributed computing open standards such as CORBA.
Web services may suffer from poor performance compared to other distributed computing
approaches such as RMI, CORBA, or DCOM.
6. Define SOAP? Mention any one security issue of it? (NOV 2016)
SOAP stands for Simple Object Access Protocol
SOAP is a communication protocol
SOAP is for communication between applications
SOAP is a format for sending messages
SOAP communicates via Internet
SOAP is platform independent
SOAP is language independent
SOAP is based on XML
SOAP is simple and extensible
SOAP allows you to get around firewalls
There are three specific security issues with web services:
1. Confidentiality
2. Authentication
Element Description
<types> A container for data type definitions used by the web service
<message> A typed definition of the data being communicated
<portType> A set of operations supported by one or more endpoints
<binding> A protocol and data format specification for a particular port type
Type Definition
One-way The operation can receive a message but will not return a response
Request-response The operation can receive a request and will return a response
Solicit-response The operation can send a request and will wait for a response
Notification The operation can send a message but will not wait for a response
25. Illustrate the benefits of Single Page Web applications. (NOV 2017)
Single Page Application (SPA) is a web application that fits on a single web page with dynamic actions
without refreshing the page. Single Page Application interactions can be handle without reaching server.
Single Page Application can improve performance in several ways like loading time, using AJAX, easy to
navigate pages etc.
Advantages:
Single Page Application is good for making Responsive Websites, Support mobile, Tablet & Desktop.
No extra queries to the server to download pages.
User friendly.
Performance Improvement, Single Page Application can improve performance in many ways, Single
time file load each of HTML, CSS, JS.
What is SOAP?
SOAP is an XML-based protocol to let applications exchange information over HTTP.
SOAP is a protocol for accessing a Web Service.
SOAP is a communication protocol
SOAP is a format for sending messages
SOAP is designed to communicate via Internet
SOAP is platform independent
SOAP is language independent
SOAP is based on XML
SOAP is simple and extensible
SOAP allows you to get around firewalls
SOAP is a W3C standard
What is UDDI?
UDDI is a directory service where companies can register and search for Web services.
UDDI stands for Universal Description, Discovery and Integration
UDDI is a directory for storing information about web services
UDDI is a directory of web service interfaces described by WSDL
UDDI communicates via SOAP
UDDI is built into the Microsoft .NET platform
Universal Description, Discovery and Integration (UDDI) are a directory service where businesses can
register and search for Web services.
What is UDDI
UDDI is a platform-independent framework for describing services, discovering businesses, and integrating
business services by using the Internet.
UDDI stands for Universal Description, Discovery and Integration
UDDI is a directory for storing information about web services
UDDI is a directory of web service interfaces described by WSDL
UDDI communicates via SOAP
UDDI is built into the Microsoft .NET platform
UDDI Benefits
Any industry or businesses of all sizes can benefit from UDDI.
Before UDDI, there was no Internet standard for businesses to reach their customers and partners
with information about their products and services. Nor was there a method of how to integrate into
each other's systems and processes.
Solving customer-driven need to remove barriers to allow for rapid participation in the global
Internet economy
Describing services and business processes programmatically in a single, open, and secure
environment
UDDI Elements
A business or company can register three types of information into a UDDI registry. This information is
contained into three elements of UDDI.
It is also possible to set up private UDDI registries. For example, a large company may set up its own private
UDDI registry for registering all internal web services. As these registries are not automatically synchronized
with the root UDDI nodes, they are not considered part of the UDDI cloud.
<businessEntity businessKey="uuid:C0E6D5A8-C446-4f01-99DA-70E212685A40"
operator="http://www.ibm.com"
authorizedName="John Doe">
<name>Acme Company</name>
<description>
We create cool Web services
</description>
<contacts>
<contact useType="general info">
<description>General Information</description>
<personName>John Doe</personName>
<phone>(123) 123-1234</phone>
<email>[email protected]</email>
</contact>
</contacts>
<businessServices>
...
</businessServices>
<identifierBag>
<keyedReference
tModelKey="UUID:8609C81E-EE1F-4D5A-B202-3EB13AD01823"
name="D-U-N-S"
value="123456789" />
</identifierBag>
<categoryBag>
<keyedReference
tModelKey="UUID:C0B9FE13-179F-413D-8A5B-5004DB8E5BB2"
name="NAICS"
value="111336" />
</categoryBag>
</businessEntity>
<businessService serviceKey="uuid:D6F1B765-BDB3-4837-828D-8284301E5A2A"
businessKey="uuid:C0E6D5A8-C446-4f01-99DA-
70E212685A40"> <name>Hello World Web Service</name>
<description>A friendly Web service</description>
<bindingTemplates>
...
</bindingTemplates>
<categoryBag />
</businessService
<bindingTemplate serviceKey="uuid:D6F1B765-BDB3-4837-828D-8284301E5A2A"
bindingKey="uuid:C0E6D5A8-C446-4f01-99DA-70E212685A40">
<description>Hello World SOAP Binding</description>
<accessPoint URLType="http">
http://localhost:8080
</accessPoint>
<tModelInstanceDetails>
<tModelInstanceInfo
tModelKey="uuid:EB1B645F-CF2F-491f-811A-4868705F5904">
<instanceDetails>
<overviewDoc>
<description>
references the description of the
WSDL service definition
</description>
<overviewURL>
http://localhost/helloworld.wsdl
</overviewURL>
</overviewDoc>
</instanceDetails>
</tModelInstanceInfo>
</tModelInstanceDetails>
</bindingTemplate>
Because a business service may have multiple binding templates, the service may specify different
implementations of the same service, each bound to a different set of protocols or a different network address.
The tModel is the last core data type, but potentially the most difficult to grasp. tModel stands for
technical model.
A tModel is a way of describing the various business, service, and template structures stored within
the UDDI registry. Any abstract concept can be registered within UDDI as a tModel. For instance, if you
define a new WSDL port type, you can define a tModel that represents that port type within UDDI.
Then, you can specify that a given business service implements that port type by associating the
tModel with one of that business service's binding templates.
<tModel tModelKey="uuid:xyz987..."
operator="http://www.ibm.com"
authorizedName="John Doe">
<name>HelloWorldInterface Port Type</name>
<description>
An interface for a friendly Web service
</description>
<overviewDoc>
<overviewURL>
http://localhost/helloworld.wsdl
</overviewURL>
</overviewDoc>
</tModel>
SOAP INTRODUCTION:
SOAP is a simple XML-based protocol to let applications exchange information over HTTP.
SOAP is a protocol for accessing a Web Service.
What is SOAP?
SOAP stands for Simple Object Access Protocol
SOAP is a communication protocol
SOAP is for communication between applications
SOAP is a format for sending messages
SOAP communicates via Internet
SOAP is platform independent
SOAP is language independent
SOAP is based on XML
SOAP is simple and extensible
SOAP allows you to get around firewalls
SOAP is a W3C recommendation
Why SOAP?
It is important for application development to allow Internet communication between programs.
Today's applications communicate using Remote Procedure Calls (RPC) between objects like DCOM
and CORBA, but HTTP was not designed for this. RPC represents a compatibility and security
problem; firewalls and proxy servers will normally block this kind of traffic.
SOAP SYNTAX:
Syntax Rules
Here are some important syntax rules:
A SOAP message MUST be encoded using XML
A SOAP message MUST use the SOAP Envelope namespace
A SOAP message MUST use the SOAP Encoding namespace
A SOAP message must NOT contain a DTD reference
A SOAP message must NOT contain XML Processing Instruction
Example
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
...
Message information goes here
...
</soap:Envelope>
Syntax
soap:encodingStyle="URI"
Example
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
...
Message information goes here
...
</soap:Envelope>
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-
envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-
encoding"> <soap:Header>
<m:Trans xmlns:m="http://www.w3schools.com/transaction/"
soap:mustUnderstand="1">234
</m:Trans>
</soap:Header>
...
...
</soap:Envelope>
The example above contains a header with a "Trans" element, a "must understand" attribute with a
value of 1, and a value of 234.
SOAP defines three attributes in the default namespace ("http://www.w3.org/2001/12/soap-
envelope"). These attributes are: must Understand, actor, and encoding Style.
The attributes defined in the SOAP Header defines how a recipient should process the SOAP
message.
Syntax
soap:actor="URI"
Syntax
soap:encodingStyle="URI"
Example
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-
envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-
encoding"> <soap:Body>
<m:GetPrice xmlns:m="http://www.w3schools.com/prices">
<m:Item>Apples</m:Item>
</m:GetPrice>
</soap:Body>
</soap:Envelope>
The example above requests the price of apples. Note that the m:GetPrice and the Item elements above
are application-specific elements. They are not a part of the SOAP namespace.
The fault code values defined below must be used in the fault code element when describing faults:
Error Description
VersionMismatch Found an invalid namespace for the SOAP Envelope element
MustUnderstand An immediate child element of the Header element, with the must Understand
attribute set to "1", was not understood
Client The message was incorrectly formed or contained incorrect information
Server There was a problem with the server so the message could not proceed
HTTP communicates over TCP/IP. An HTTP client connects to an HTTP server using TCP. After
establishing a connection, the client can send an HTTP request message to the server:
POST /item HTTP/1.1
Host: 189.123.255.239
Content-Type: text/plain
Content-Length: 200
The server then processes the request and sends an HTTP response back to the client. The
response contains a status code that indicates the status of the request:
200 OK Content-Type:
text/plain Content-
Length: 200
In the example above, the server returned a status code of 200. This is the standard success code
for HTTP.
If the server could not decode the request, it could have returned something like this:
400 Bad Request
Content-Length: 0
Content-Type
The Content-Type header for a SOAP request and response defines the MIME type for the message
and the character encoding (optional) used for the XML body of the request or response.
Syntax
Content-Type: MIMEType; charset=character-encoding
Content-Length
The Content-Length header for a SOAP request and response specifies the number of bytes in the
body of the request or response.
Syntax
Content-Length: bytes
SOAP request:
POST /InStock HTTP/1.1
Host: www.example.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPrice>
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
SOAP response:
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPriceResponse>
<m:Price>34.5</m:Price>
</m:GetStockPriceResponse>
</soap:Body>
</soap:Envelope>
WSDL (Web Services Description Language) is an XML-based language for describing Web services and
how to access them.
Introduction to WSDL
WSDL is an XML-based language for describing Web services and how to access them.
What is WSDL?
WSDL stands for Web Services Description Language
WSDL is written in XML
WSDL is an XML document
WSDL is used to describe Web services
WSDL is also used to locate Web services
WSDL is a W3C recommendation
WSDL Documents
A WSDL document is just a simple XML document.
It contains set of definitions to describe a web service.
Element Description
<types> A container for data type definitions used by the web service
<message> A typed definition of the data being communicated
<portType> A set of operations supported by one or more endpoints
<binding> A protocol and data format specification for a particular port type
WSDL Ports:
The <portType> element is the most important WSDL element.
It describes a web service, the operations that can be performed, and the messages that are involved.
The <portType> element can be compared to a function library (or a module, or a class) in a
traditional programming language.
WSDL Messages
The <message> element defines the data elements of an operation.
Each message can consist of one or more parts. The parts can be compared to the parameters of a
function call in a traditional programming language.
WSDL Types
The <types> element defines the data types that are used by the web service.
For maximum platform neutrality, WSDL uses XML Schema syntax to define data types.
WSDL Bindings
The <binding> element defines the data format and protocol for each port type.
In this example the <portType> element defines "glossaryTerms" as the name of a port, and
"getTerm" as the name of an operation.
The "getTerm" operation has an input message called "getTermRequest" and an output message
called "getTermResponse".
The <message> elements define the parts of each message and the associated data types.
Compared to traditional programming, glossaryTerms is a function library, "getTerm" is a function
with "getTermRequest" as the input parameter, and getTermResponse as the return parameter.
WSDL PortType
The <portType> element is the most important WSDL element.
One-Way Operation
A one-way operation example:
<message name="newTermValues">
<part name="term" type="xs:string"/>
<part name="value" type="xs:string"/>
</message>
<portType name="glossaryTerms">
<operation name="setTerm">
<input name="newTerm" message="newTermValues"/>
</operation>
</portType >
In the example above, the portType "glossaryTerms" defines a one-way operation called "setTerm".
The "setTerm" operation allows input of new glossary terms messages using a "newTermValues"
message with the input parameters "term" and "value". However, no output is defined for the
operation.
Request-Response Operation
A request-response operation example:
<message name="getTermRequest">
<part name="term"
type="xs:string"/> </message>
<message name="getTermResponse"> <part
name="value" type="xs:string"/>
</message>
5. Explain about Web Service Architecture (WSA)? (11 MARKS) (NOV 2016)
2. Service requestor
Business that requires certain functions to be satisfied.
Application looking for and invoking an interaction with a service.
3. Service registry
Searchable registry of service descriptions where service providers publish their
service descriptions.
6. Explain briefly about AJAX –improving web page performance using AJAX? (11 MARKS) (NOV
2016, 2017)
AJAX Introduction
AJAX is about updating parts of a web page, without reloading the whole page.
Google Suggest
AJAX was made popular in 2005 by Google, with Google Suggest.
Google Suggest is using AJAX to create a very dynamic web interface: When you start typing in Google's
search box, a JavaScript sends the letters off to a server and the server returns a list of
suggestions.
CSS-Allows for a clear separation of the presentation style from the content and may be changed
programmatically by JavaScript.
XMLHttpRequest- JavaScript object that performs asynchronous interaction with the server.
When the user interacts with the page, the client creates an XMLHttpRequest object to manage a request (Step
1). The XMLHttpRequest object sends the request to the server (Step 2) and awaits the response. The requests
are asynchronous, so the user can continue interacting with the application on the client-side while the
server processes the earlier request concurrently. Other user interactions could result in additional requests
to the server (Steps 3 and 4). Once the server responds to the original request (Step 5), the XMLHttpRequest
object that issued the request calls a client-side function to process the data returned by the server. This
function—known as a callback function— uses partial page updates (Step 6) to display the data in the
existing web page without reloading the entire page. At the same time, the server may
be responding to the second request (Step 7) and the client-side may be starting to do another partial page
update (Step 8). The callback function updates only a designated part of the page. Such partial page updates
help make web applications more responsive, making them feel more like desktop applications. The web
application does not load a new page while the user interacts with it.
AJAX Example
To understand how AJAX works, we will create a small AJAX application:
<html>
<head>
<script>
function loadXMLDoc() {
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change
Content</button> </body>
</html>
Next, add a <script> tag to the page's head section. The script section contains the loadXMLDoc() function:
<head>
<script>
function loadXMLDoc()
{
.... AJAX script goes here ...
}
</script>
</head>
AJAX XMLHttpRequest:
AJAX - Create an XMLHttpRequest Object
The keystone of AJAX is the XMLHttpRequest object.
Old versions of Internet Explorer (IE5 and IE6) uses an ActiveX Object:
variable=new ActiveXObject("Microsoft.XMLHTTP");
To handle all modern browsers, including IE5 and IE6, check if the browser supports the XMLHttpRequest
object. If it does, create an XMLHttpRequest object, if not, create an ActiveXObject:
Example
var xmlhttp;
if (window.XMLHttpRequest)
{ // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{ // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
Method Description
Specifies the type of request, the URL, and if the request should be
handled asynchronously or not.
open(method,url,async) method: the type of request: GET or POST
url: the location of the file on the server
async: true (asynchronous) or false (synchronous)
Sends the request off to the server.
send(string)
string: Only used for POST requests
GET
Property Description
Example
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
Example
Request the file cd_catalog.xml and parse the response:
xmlDoc=xmlhttp.responseXML;
txt="";
x=xmlDoc.getElementsByTagName("ARTIST");
for (i=0;i<x.length;i++)
{
txt=txt + x[i].childNodes[0].nodeValue + "<br>";
}
document.getElementById("myDiv").innerHTML=txt;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
</html>
Output:
AJAX is not a new programming language.
AJAX is a technique for creating fast and dynamic web pages.