1. S.Hrushikesava Raju,Associate Professor, CSE Dept., SIETK,Narayanavanam Road,Puttur Page 1
UNIT – 5 : AJAX, WSDL and SOAP
Contents:
5.1 AJAX and PHP: Similarities, Why we need to combine AJAX and PHP.
5.2 WSDL: Definition, Purpose
5.3 SOAP: Definition, Purpose
5.1 AJAX: AJAX stands for Asynchronous Java Script and XML. It allow the various client requests at
the server, the server should process the required processing, and automatically loads the page without
refreshing the page i.e without user need to move from one page to other page.
The following is the traditional client server model in which server after receive the requests from
clients, perform required processing, and shows the updated content on the web page when page is
refreshed only.
AJAX is based on the following architecture called internet request/response model using AJAX’s
asynchronous methodology.
The new ergonomic changes can occur on the new page without refreshing / user need not move the
pages.
XMLHTTPRequst: The XMLHTTPRequest object is instantiated for AJAX. This is created as an
ActiveX control by the Microsoft, whereas firefox and safari use basic Javascript object.
Methods:
a) Abort(): It stop the current request. When request is made to stop the request for a certain length
of time, this method is called.
b) getAllResponseHeaders(): It acquire full information on all HTTP headers which are being
passed.
Web page Server
New Content
on the page
after refresh
request response
Fig: Traditional server request and response
model
Web page
Web Server
Request / Response1
Request / Response2
Request / Response3
2. S.Hrushikesava Raju,Associate Professor, CSE Dept., SIETK,Narayanavanam Road,Puttur Page 2
c) getResponseHeader(“headername”): This get information of particular part of the header.
Example: getResponse Header(“content-length”) is used to obtain size of the particular
document.
d) Open(“method”,”url”,”async”,”username”,”pass”) : This open a connection to a specific file
on the server.
e) setRequestHeader(“label”,”value”): This give a label of sorts to a header by passing string
label, and value of the label.
f) Send(“content”): This send request to the server. The response will be received immediately if
the request is sent asynchronously. This is allowed to send form element values.
Properties: Every object will have a complete set of properties which can be manipulated to obtain the
required work.
a) onreadyStateChange: This is an event handler by which to trigger certain blocks of code or
functions when there is change of state.
b) readyState: This will give full information of part of process of the current request. It is useful
for exceptional handling and is considered to be important while deciding to perform certain
actions.
c) responseText: This return script output in the form of text after request gone through.
d) responseXML: This return the response of the script in the XML format only.
e) Status: This is the response code returned from the request. Ex: status denote 404 if the request
is not found.
f) statusText: This return the response code in the text so that user can know in depth knowledge
about the error.
8.3 AJAX and PHP: In PHP, the large community of developers can share the PHP code although the
code is hidden on the web. The AJAX which is Java Script based technology used at client side, and the
code is not hidden.
AJAX is Java script based technology. This is open sort of technology that won’t hide the code. The
code written in java script can be viewed as client side technology
PHP and AJAX work very well together due to their functionalities. PHP is robust, object oriented
language, and AJAX is java based technology and is a robust language, but modeled after object
oriented model. Hence, both the technologies are combined to obtain best solution for future use.
Therefore, when both of them combined, best outcome will be out and good results are obtained when
merged.
5.2 WSDL:
Web Services Description Language (WSDL)
Web Services Description Language (WSDL) is a format for describing a Web Services interface. It is a
way to describe services and how they should be bound to specific network addresses. WSDL has three
parts:
3. S.Hrushikesava Raju,Associate Professor, CSE Dept., SIETK,Narayanavanam Road,Puttur Page 3
• Definitions
• Operations
• Service bindings
Definitions are generally expressed in XML and include both data type definitions and message
definitions that use the data type definitions. These definitions are usually based upon some agreed upon
XML vocabulary. This agreement could be within an organization or between organizations.
Vocabularies within an organization could be designed specifically for that organization. They may or
may not be based on some industry-wide vocabulary. If data type and message definitions need to be
used between organizations, then most likely an industry-wide vocabulary will be used. For more on
XML vocabularies, click here.
XML, however, is not necessary required for definitions. The OMG Interface Definition Language
(IDL), for example, could be used instead of XML. If a different definitional format were used, senders
and receivers would need to agree on the format as well as the vocabulary. Nevertheless, over time,
XML-based vocabularies and messages are likely to dominate. XML Namespaces are used to ensure
uniqueness of the XML element names in the definitions, operations, and service bindings.
Operations describe actions for the messages supported by a Web service. There are four types of
operations:
• One-way: Messages sent without a reply required
• Request/response: The sender sends a message and the received sends a reply.
• Solicit response: A request for a response. (The specific definition for this action is pending.)
• Notification: Messages sent to multiple receivers. (The specific definition for this action is
pending.)
Operations are grouped into port types. Port types define a set of operations supported by the Web
service.
Service bindings connect port types to a port. A port is defined by associating a network address with a
port type. A collection of ports defines a service. This binding is commonly created using SOAP, but
other forms may be used. These other forms could include CORBA Internet Inter-ORB Protocol (IIOP),
DCOM, .NET, Java Message Service (JMS), or WebSphere MQ to name a few.
The following figure shows the relationship of the basic parts of WSDL:
4. S.Hrushikesava Raju,Associate Professor, CSE Dept., SIETK,Narayanavanam Road,Puttur Page 4
5.3 SOAP:
SOAP
SOAP provides the envelope for sending Web Services messages over the Internet/Internet. It is part of
the set of standards specified by the W3C. SOAP is an alternative to Representational State Transfer
(REST) and JavaScript Object Notation (JSON).
OAP is an acronym for Simple Object Access Protocol. It is an XML-based messaging protocol for
exchanging information among computers. SOAP is an application of the XML specification.
Points to Note
• SOAP is a communication protocol designed to communicate via Internet.
• SOAP can extend HTTP for XML messaging.
• SOAP provides data transport for Web services.
• SOAP can exchange complete documents or call a remote procedure.
• SOAP can be used for broadcasting a message.
• SOAP is platform- and language-independent.
• SOAP is the XML way of defining what information is sent and how.
• SOAP enables client applications to easily connect to remote services and invoke remote
methods.
Although SOAP can be used in a variety of messaging systems and can be delivered via a variety of
transport protocols, the initial focus of SOAP is remote procedure calls transported via HTTP.
Other frameworks including CORBA, DCOM, and Java RMI provide similar functionality to SOAP, but
SOAP messages are written entirely in XML and are therefore uniquely platform- and language-
independent.
5. S.Hrushikesava Raju,Associate Professor, CSE Dept., SIETK,Narayanavanam Road,Puttur Page 5
The SOAP envelope contains two parts:
1. An optional header providing information on authentication, encoding of data, or how a recipient of a
SOAP message should process the message.
2. The body that contains the message. These messages can be defined using the WSDL specification.
SOAP commonly uses HTTP, but other protocols such as Simple Mail Transfer Protocol (SMTP) may
by used. SOAP can be used to exchange complete documents or to call a remote procedure.
NOTE: SOAP at one time stood for Simple Object Access Protocol. Starting with SOAP Version 1.2,
the letters in the acronym have no particular meaning.
• 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
Why SOAP?
It is important for web applications to be able to communicate over the Internet.
The best way to communicate between applications is over HTTP, because HTTP is supported by all
Internet browsers and servers. SOAP was created to accomplish this.
SOAP provides a way to communicate between applications running on different operating systems,
with different technologies and programming languages.
6. S.Hrushikesava Raju,Associate Professor, CSE Dept., SIETK,Narayanavanam Road,Puttur Page 6
SOAP Building Blocks
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
All the elements above are declared in the default namespace for the SOAP envelope:
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 Instructions
Skeleton SOAP Message
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Header>
...
</soap:Header>
7. S.Hrushikesava Raju,Associate Professor, CSE Dept., SIETK,Narayanavanam Road,Puttur Page 7
<soap:Body>
...
<soap:Fault>
...
</soap:Fault>
</soap:Body>
</soap:Envelope>
Example:
he SOAP Envelope Element
The required SOAP Envelope element is the root element of a SOAP message. This element defines the
XML document as a SOAP message.
Example
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
...
Message information goes here
...
</soap:Envelope>
The xmlns:soap Namespace
Notice the xmlns:soap namespace in the example above. It should always have the value of:
"http://www.w3.org/2003/05/soap-envelope/".
The namespace defines the Envelope as a SOAP Envelope.
If a different namespace is used, the application generates an error and discards the message.
The encodingStyle Attribute
The encodingStyle attribute is used to define the data types used in the document. This attribute may
appear on any SOAP element, and applies to the element's contents and all child elements.
A SOAP message has no default encoding.
8. S.Hrushikesava Raju,Associate Professor, CSE Dept., SIETK,Narayanavanam Road,Puttur Page 8
Syntax
soap:encodingStyle="URI"
Example
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
...
Message information goes here
...
</soap:Envelope>
The SOAP Header Element
The optional SOAP Header element contains application-specific information (like authentication,
payment, etc) about the SOAP message.
If the Header element is present, it must be the first child element of the Envelope element.
Note: All immediate child elements of the Header element must be namespace-qualified.
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Header>
<m:Trans xmlns:m="https://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 "mustUnderstand" attribute with a value
of 1, and a value of 234.
SOAP defines three attributes in the default namespace. These attributes are: mustUnderstand, actor, and
encodingStyle.
The attributes defined in the SOAP Header defines how a recipient should process the SOAP message.
9. S.Hrushikesava Raju,Associate Professor, CSE Dept., SIETK,Narayanavanam Road,Puttur Page 9
The mustUnderstand Attribute
The SOAP mustUnderstand attribute can be used to indicate whether a header entry is mandatory or
optional for the recipient to process.
If you add mustUnderstand="1" to a child element of the Header element it indicates that the receiver
processing the Header must recognize the element. If the receiver does not recognize the element it will
fail when processing the Header.
Syntax
soap:mustUnderstand="0|1"
Example
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Header>
<m:Trans xmlns:m="https://www.w3schools.com/transaction/"
soap:mustUnderstand="1">234
</m:Trans>
</soap:Header>
...
...
</soap:Envelope>