SlideShare a Scribd company logo
WEB-SERVICES
INTRODUCTION The root of WEB-SERVICES can be traced out when the concept of component architecture began taking shape. Beauty of Component architecture is develop on one platform and run in different platform Distributed Computing RMI CORBA COM  WEB-BASED Application JSP SERVLET
WEB-SERVICES as named suggest service available on the web. This network may be LAN,WAN,MAN or Internet IBM says :  internet based modular application that perform a specific business task and confirm to a specific technical format A practical example of a web-services is one company calling services of other company to directly pass on a purchase order through internet connection
Characteristics of WEB-SERVICES A web-services can be accessed over the WEB The service interface helps the web-services to be called any other programme or services. The service interface is an XML document since XML has emerged as the global data exchange technology A web-services can be registered in a service registry to be accessed by other programme Web-services use the standers Web protocol to communicate
Life Cycle of Web-services A web-service needs to be created  The service interface and invocation method should be defined The web-service should be published on the internet or intranet to facilitate the web user in using the service The web user should be able to find the web-service The web-service should be invoked The web-service should be unpublished when no longer in use.
Requirement for creating a web-services Representing data in a standard format  : XML  is emerged as standers way to represent data. A common extensible message format : A simple Object access protocol ( SOAP ) is a light weight protocol for exchange information. A common extensible, service descripting language : A web services description language ( WSDL ) is used to document the same for Web-services. A list of service providers and the services offered by them :  Universal Description Discovery and integration ( UDDI ) is a industry initiated project, which satisfying the requirement of maintaining registries.
Working of the Web-services A web-service consist a file which contain either a class providing a functionality of web-services or reference of the external class. This information is an XML file known as WSDL file.  Depending on the requirments, the client invokes the web method of the service and send and receive the parameter from the method. The server then returns the appropriate result to the client
Web-services which run over the HTTP can be accessed by following ways: HTTP GET: HTTP POST : SOAP  : Soap messaging is the proper way to call a web-services. The Get and Post method is are useful if a web-services is to be called quickly and no soap client  is available. These operation will support simple inputs and outputs. SOAP is used whenever there exist a need to pass complex objects and data
Advantages of Web-services Cross buisness integration Improved efficiency Closer customer relationships Facilitates just-in-time relationships Reduce complexity Disadvantages: Network Security risk XML support is necessary Cost of deploying is high
Introduction to XML
What is XML? XML stands for  E X tensible  M arkup  L anguage   XML is a  markup language  much like HTML.  XML was designed to  describe data .   XML tags are not predefined in XML. You must  define your own tags .  XML is  self describing .  XML uses a DTD  ( Document Type Definition )  to formally describe the data.
Difference between XML and HTML   XML is  not a replacement  for HTML. XML and HTML were designed with  different goals : XML was designed to  describe data  and to focus on  what data is . HTML was designed to  display data  and to focus on  how data looks . HTML is about  displaying  information, XML is about  describing  information.
XML is eXtensible  : The tags used to markup HTML documents and the structure of HTML documents are  predefined . The author of HTML documents can only use tags that are defined  in the HTML standard . XML allows the author to  define his own tags  and his own document structure. It is important to understand that  XML is not a replacement for HTML .  In the future development of the Web it is most likely that XML will be used to structure and describe the Web data, while HTML will be used to format and display the same data.
How can XML be used? XML can keep data separated from your HTML XML can be used to store data inside HTML documents  XML can be used as a format to exchange information  XML can be used to store data in files or in databases
XML Syntax   <?xml version=&quot;1.0&quot;?>  <note> <to>Tove</to> <from>Jani</from>  <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>  The first line in the document:  The XML declaration  should always be included. It defines the XML version of the document. The next line defines the first element of the document (the root element  The next lines defines 4 child elements of the root (to, from, heading, and body):
All XML elements must have a closing tag XML tags are case sensitive   All XML elements must be properly nested  All XML documents must have a root tag Attribute values must always be quoted <?xml version=&quot;1.0&quot;?> <note date=&quot;12/11/99&quot;>  …………… </note>
XML Attributes   XML attributes are normally used to describe XML elements, or to provide additional information about elements  <?xml version=&quot;1.0&quot;?> <note date=&quot;12/11/99&quot;> <to>Tove</to> <from>Jani</from>  <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
Using an Attribute for sex: <person sex=&quot;female&quot;> <firstname>Anna</firstname>  <lastname>Smith</lastname> </person> Using an Element for sex: <person>  <sex>female</sex>  <firstname>Anna</firstname>  <lastname>Smith</lastname> </person>
There are no fixed rules about when to use attributes to describe data, and when to use elements. Attributes are handy in HTML, but in  XML you should try to avoid them , as long as the same information can be expressed using elements. Problems with attributes :  attributes can not contain multiple values (elements can)  attributes are not expandable (for future changes)  attributes can not describe structures (like child elements can)  attributes are more difficult to manipulate by program code  attribute values are not easy to test against a DTD
XML Validation   A  &quot;Well Formed&quot;  XML document is a document that conforms to the XML syntax rules that we described earlier. A  &quot;Valid&quot;  XML document is a &quot;Well Formed&quot; XML document which  conforms to the rules of a Document Type Definition (DTD). The following is the same document as above but with an added reference to a DTD: <?xml version=&quot;1.0&quot;?>  <!DOCTYPE note SYSTEM &quot;InternalNote.dtd&quot;>  <note>  <to>Tove</to>  …………… </note>
XML DTD - An Introduction to XML Document Type Definitions The purpose of a DTD is to define the legal building blocks of an XML document. It defines the document structure with a list of legal elements. Internal DTD External DTD Use of DTD :  XML provides an application independent way of sharing data. With a DTD, independent groups of people can agree to use a common DTD for interchanging data. Your application can use a standard DTD to verify that data that you receive from the outside world is valid. You can also use a DTD to verify your own data.
Internal DTD <?xml version=&quot;1.0&quot;?> <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)>  <!ELEMENT body (#PCDATA)> ]>  <note>  <to>Tove</to> <from>Jani</from> <heading>Reminder</heading>  <body>Don't forget me this weekend!</body> </note>
External DTD <?xml version=&quot;1.0&quot;?>  <!DOCTYPE note SYSTEM &quot;note.dtd&quot;> <note> …………… ..  </note>  <?xml version=&quot;1.0&quot;?> <!ELEMENT note (to,from,heading,body)>  <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)>  <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>
DTD - XML building blocks   XML documents (and HTML documents) are made up by the following building blocks: Elements  : Elements are the main building blocks of both XML and HTML documents.  Tags  : Tags are used to markup elements. A starting tag like <element_name> mark up the beginning of an element, and an ending tag like </element_name> mark up the end of  an element Attributes  : Attributes provide extra information about elements. .
PCDATA  :  PCDATA means parsed character data.Think of character data as the text found between the start tag and the end tag of an XML element.PCDATA is text that will be parsed by a parser. Tags inside the text will be treated as markup and entities will be expanded.  CDATA  :  CDATA also means character data.CDATA is text that will NOT be parsed by a parser. Tags inside the text will NOT be treated as markup and entities will not be expanded Entities  : Most of you will known the HTML entity reference: &quot;&nbsp;&quot;  that is used to insert an extra space in an HTML document. Entities are expanded when a document is parsed by an XML parser.
Declaring an Element   <!ELEMENT element-name (element-content)>  Empty Tag  : <!ELEMENT img (EMPTY)>  Elements with data  :  <!ELEMENT note (#PCDATA)> Elements with children (sequences)  :  <!ELEMENT note (to,from,heading,body)>  Declares that the child element message can only occur one time inside the note element :  <!ELEMENT note (message)>
The + sign declares that the child element message must occur one or more times inside the note element :  <!ELEMENT note (message+)>  The * sign declares that the child element message can occur zero or more times inside the note element  <!ELEMENT note (message*)>   The ? sign declares that the child element message can occur zero or one times inside the note element. <!ELEMENT note (message?)>   Define This :  <!ELEMENT note (to+,from,header,message*,#PCDATA)>
Declaring Attributes   <!ATTLIST element-name attribute-name attribute-type  default-value>   Attribute-type :   CDATA  :The value is character data ID  : The value is an unique id  IDREF  : The value is the id of another element ENTITY  : The value is an entity  Xml  : The value is predefined
attribute-default-value   #DEFAULT   value  : The attribute has a default value #REQUIRED  : The attribute value must be included in    the element #IMPLIED  : The attribute does not have to be included #FIXED value  :  The attribute value is fixed XML example: <square width=&quot;100&quot;></square>   DTD example: <!ELEMENT square EMPTY>   <!ATTLIST square width CDATA &quot;0&quot;>
XML NAMESPACE XML Namespaces provide a method to avoid element name conflicts  In XML, element names are defined by the developer. This often results in a conflict when trying to mix XML documents from different XML applications
This XML carries HTML table information: <table> <tr>  <td>Apples</td> <td>Bananas</td>  </tr>  </table>  This XML carries information about a table (a piece of furniture):   <table> <name>African Coffee Table</name> <width>80</width>  <length>120</length>  </table>
If these XML fragments were added together, there would be a name conflict. Both contain a <table> element, but the elements have different content and meaning. An XML parser will not know how to handle these differences XML Namespaces - The xmlns Attribute When using prefixes in XML, a so-called  namespace  for the prefix must be defined. The namespace is defined by the  xmlns attribute  in the start tag of an element. The namespace declaration has the following syntax.  xmlns: prefix =&quot; URI &quot;.
<root> <h:table xmlns:h=&quot;http://www.w3.org/TR/html4/&quot;>  <h:tr>  <h:td>Apples</h:td>  <h:td>Bananas</h:td>  </h:tr>  </h:table> <f:table xmlns:f=&quot;http://www.w3schools.com/furniture&quot;>  <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> </root>  In the example above, the xmlns attribute in the <table> tag give the h: and f: prefixes a qualified namespace  When a namespace is defined for an element, all child elements with the same prefix are associated with the same namespace.
XML SCHEMA The purpose of an XML Schema is to define the legal building blocks of an XML document, just like a DTD. An XML Schema: defines elements that can appear in a document  defines attributes that can appear in a document  defines which elements are child elements  defines the order of child elements  defines the number of child elements  defines whether an element is empty or can include text  defines data types for elements and attributes  defines default and fixed values for elements and attributes
We think that very soon XML Schemas will be used in most Web applications as a replacement for DTDs. Here are some reasons: XML Schemas are extensible to future additions  XML Schemas are richer and more powerful than DTDs  XML Schemas are written in XML  XML Schemas support data types. XML Schemas support namespaces
XML Schemas Support Data Types   One of the greatest strength of XML Schemas is the support for data types.With support for data types : It is easier to describe allowable document content  It is easier to validate the correctness of data  It is easier to work with data from a database  It is easier to define data facets (restrictions on data)  It is easier to define data patterns (data formats)  It is easier to convert data between different data types
XML Schemas use XML Syntax   You don't have to learn a new language You can use your XML editor to edit your Schema files You can use your XML parser to parse your Schema files  You can manipulate your Schema with the XML DOM  You can transform your Schema with XSLT
XML Schemas Secure Data Communication   With XML Schemas, the sender can describe the data in a way that the receiver will understand.  A date like: &quot;03-11-2004&quot; will, in some countries, be interpreted as 3.November and in other countries as 11.March.However, an XML element with a data type like this: <date type=&quot;date&quot;>2004-03-11</date> ensures a mutual understanding of the content, because the XML data type &quot;date&quot; requires the format &quot;YYYY-MM-DD&quot;.
A Simple XML Document (note.xml) <?xml version=&quot;1.0&quot;?> <note>  <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
A DTD File (note.dtd) <!ELEMENT note (to, from, heading, body)> <!ELEMENT to (#PCDATA)>  <!ELEMENT from (#PCDATA)>  <!ELEMENT heading (#PCDATA)>  <!ELEMENT body (#PCDATA)>  The first line defines the note element to have four child elements: &quot;to, from, heading, body&quot;.
An XML Schema (note.xsd) <?xml version=&quot;1.0&quot;?> <xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; targetNamespace=&quot;http://www.w3schools.com&quot; xmlns=&quot;http://www.w3schools.com&quot; elementFormDefault=&quot;qualified&quot;> <xs:element name=&quot;note&quot;>  <xs:complexType>  <xs:sequence> <xs:element name=&quot;to&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;from&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;heading&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;body&quot; type=&quot;xs:string&quot;/> </xs:sequence>  </xs:complexType>  </xs:element></xs:schema>
<?xml version=&quot;1.0&quot;?> 1.<xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; 2.targetNamespace=&quot;http://www.w3schools.com&quot; 3.xmlns=&quot;http://www.w3schools.com&quot; 4.elementFormDefault=&quot;qualified&quot;> ............................................ </xs:schema>  1.indicates that the elements and data types used in the schema come from the &quot;http://www.w3.org/2001/XMLSchema&quot; namespace  2.indicates that the elements defined by this schema (note, to, from, heading, body.) come from the &quot;http://www.w3schools.com&quot; namespace  3.indicates that the default namespace is &quot;http://www.w3schools.com&quot;.  4.indicates that any elements used by the XML instance document which were declared in this schema must be namespace qualified .
DTD reference in XML : <?xml version=&quot;1.0&quot;?> <!DOCTYPE note SYSTEM &quot;http://www.w3schools.com/dtd/note.dtd&quot;>  <note> ……… .…................... </note> Schema reference in XML :  <?xml version=&quot;1.0&quot;?> <note xmlns=&quot;http://www.w3schools.com&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://www.w3schools.com note.xsd&quot;>  ……………………………… </note>
<?xml version=&quot;1.0&quot;?> <note xmlns=&quot;http://www.w3schools.com&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://www.w3schools.com note.xsd&quot;>  ………………………… .. </note> specifies the default namespace declaration   Once you have the XML Schema Instance namespace available : xmlns:xsi= http://www.w3.org/2001/XMLSchema-instance you can use the schemaLocation attribute. This attribute has two values. The first value is the namespace to use. The second value is the location of the XML schema to use for that namespace : xsi:schemaLocation=&quot;http://www.w3schools.com note.xsd&quot;
Style Sheet <?xml version=&quot;1.0&quot; encoding=&quot;ISO8859-1&quot; ?> <?xml:stylesheet href=&quot;cd_catalog.css&quot; type=&quot;text/css&quot;?> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> ……… .. </CD>
<HTML> <BODY>CATALOG { width: 100%; } CD { display: block; margin-bottom: 30pt; margin-left: 0; } TITLE { color: blue; font-size: 20pt; } ARTIST { color: green; font-size: 20pt; } COUNTRY,PRICE,YEAR,COMPANY { Display: block; color: red; margin-left: 20pt; }</BODY></HTML>
XSLT XSLT stands for XSL Transformations. It is use to transform XML documents into other formats, like XHTML.  XSL : XSL stands for EXtensible Stylesheet Language. XSLT stands for XSL Transformations  XSLT is the most important part of XSL  XSLT transforms an XML document into another XML document  XSLT uses XPath to navigate in XML documents  XSLT is a W3C Recommendation
Catalog.xml :   <?xml version=&quot;1.0&quot; ?> <?xml:stylesheet href=&quot;catalog.xsl&quot; type=&quot;text/xsl&quot;?> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> ………… .
catalog.xsl  :   <?xml version='1.0'?> <xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/TR/WD-xsl&quot;> <xsl:template match=&quot;/&quot;> <html> <body> <table border=&quot;2&quot; bgcolor=&quot;yellow&quot;> <tr> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select=&quot;CATALOG/CD&quot;> <tr> <td><xsl:value-of select=&quot;TITLE&quot;/></td> <td><xsl:value-of select=&quot;ARTIST&quot;/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
The  match  attribute is used to associate a template with an XML element . match=&quot;/&quot; defines the whole document. The <xsl:value-of> element can be used to extract the value of an XML element and add it to the output stream of the transformation  The XSL <xsl:for-each> element can be used to select every XML element of a specified node-set  <xsl:for-each select=&quot;catalog/cd[artist='Bob Dylan']&quot;>   Legal filter operators are: =  (equal)  != (not equal)  &lt; less than  &gt; greater than
To sort the output, simply add an <xsl:sort> element inside the <xsl:for-each> element in the XSL file:  <?xml version='1.0'?> ………………… . <xsl:for-each select=&quot;catalog/cd&quot;>   <xsl:sort select=&quot;artist&quot;/> <tr>  <td><xsl:value-of select=&quot;title&quot;/></td> <td><xsl:value-of select=&quot;artist&quot;/></td>   </tr>  </xsl:for-each>  …………………………………… . </xsl:stylesheet>
To add a conditional test, add the <xsl:if> element inside the <xsl:for-each> element in the XSL file: <?xml version='1.0'?> ………………… . <xsl:for-each select=&quot;catalog/cd&quot;> <xsl:if test=&quot;price &gt; 10&quot;> <tr>  <td><xsl:value-of select=&quot;title&quot;/></td> <td><xsl:value-of select=&quot;artist&quot;/></td> </tr> </xsl:if> </xsl:for-each>  …………………………………… . </xsl:stylesheet
To insert a multiple conditional test against the XML file, add the <xsl:choose>, <xsl:when>, and <xsl:otherwise> elements to the XSL file: <xsl:for-each select=&quot;catalog/cd&quot;> <tr>  <td><xsl:value-of select=&quot;title&quot;/></td> <xsl:choose> <xsl:when test=&quot;price &gt; 10&quot;>  <td bgcolor=&quot;#ff00ff&quot;>  <xsl:value-of select=&quot;artist&quot;/> </td>  </xsl:when> <xsl:otherwise>   <td><xsl:value-of select=&quot;artist&quot;/></td> </xsl:otherwise>  </xsl:choose> </tr>  </xsl:for-each>
Simple object Access protocol (SOAP 1.2)
Introduction SOAP is a lightweight protocol intended for exchanging structured information in a decentralized, distributed environment SOAP uses XML technologies to define an extensible messaging framework providing a message construct that can be exchanged over a variety of underlying protocols The framework has been designed to be independent of any particular programming model and other implementation specific semantics Wire protocol similar to :    IIOP for CORBA JRMP for RMI Supports XML-based RPC (Remote Procedure Call)
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 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 will be developed as a  W3C standard
WHAT SOAP IS  NOT  ? Not a component model So it will not replace objects and components, i.e. EJB™,  JavaBeans™ Not a programming language   So it will not replace Java Not a solution for all So it will not replace other distributed computing technologies such as RMI
SOAP Message structure SOAP Envelope SOAP Header Header Entry Header Entry SOAP Body Body Entry Body Entry
A SOAP message is an ordinary XML document containing the following elements: A required Envelope element that identifies the XML document as a SOAP message  An  optional  Header element that contains header information  A  required  Body element that contains call and response information  An  optional  Fault element that provides information about errors that occurred while processing the message 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
<?xml version=&quot;1.0&quot;?>  <soap:Envelope xmlns:soap =&quot;http://www.w3.org/2001/12/soap-envelope &quot; soap:encodingStyle=&quot; http://www.w3.org/2001/12/soap-encoding &quot;> <soap:Header> ... ...  </soap:Header> <soap:Body>  ...  ...  <soap:Fault> ... ...  </soap:Fault>  </soap:Body> </soap:Envelope>
The SOAP Envelope Element   The required SOAP Envelope element is the root element of a SOAP message. It defines the XML document as a SOAP message.  The SOAP encodingStyle attribute is used to define the data types used in the document. This attribute may appear on any SOAP element, and it will apply to that element's contents and all child elements. A SOAP message has no default encoding.
SOAP Header 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  SOAP defines three attributes in the default namespace (&quot;http://www.w3.org/2001/12/soap-envelope&quot;).  These attributes are:  actor ,  mustUnderstand , and  encodingStyle . The attributes defined in the SOAP Header defines how a recipient should process the SOAP message
Actor attribute  : A SOAP message may travel from a sender to a receiver by passing different endpoints along the message path.  Syntax :  soap:actor= “uri” <?xml version=&quot;1.0&quot;?>  <soap:Envelope xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;> <soap:Header> <m:Trans xmlns:m=&quot;http://www.w3schools.com/transaction/&quot;  soap:actor=&quot;http://www.w3schools.com/appml /&quot;> 234 </m:Trans> </soap:Header> ... ... </soap:Envelope>  The example above contains a header with a &quot;Trans&quot; element
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 &quot;mustUnderstand=&quot;1&quot; to a child element of the Header element it indicates that the receiver processing the Header must recognize the element.  Syntax :  soap:mustUnderstand=&quot;0|1&quot;   <?xml version=&quot;1.0&quot;?> <soap:Envelope xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;> <soap:Header>  <m:Trans xmlns:m=&quot;http://www.w3schools.com/transaction/&quot;  soap:mustUnderstand=&quot;1&quot;>  234 </m:Trans> </soap:Header> ... ... </soap:Envelope>
SOAP Body The required SOAP Body element contains the actual SOAP message  SOAP defines one element inside the Body element in the default namespace (&quot;http://www.w3.org/2001/12/soap-envelope&quot;). This is the SOAP Fault element, which is used to indicate error messages.
<?xml version=&quot;1.0&quot;?> <soap:Envelope xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;> <soap:Body>  <m:GetPrice xmlns:m=&quot;http://www.w3schools.com/prices&quot;>  <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 standard.
A SOAP response looks like this : <?xml version=&quot;1.0&quot;?>  <soap:Envelope xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;> <soap:Body> <m:GetPriceResponse xmlns:m=&quot;http://www.w3schools.com/prices&quot;>  <m:Price>1.90</m:Price> </m:GetPriceResponse> </soap:Body> </soap:Envelope>
SOAP Fault Element   An error message from a SOAP message is carried inside a Fault element. If a Fault element is present, it must appear as a child element of the Body element. A Fault element can only appear once in a SOAP message. Information about who caused the fault to happen  <faultactor> Holds application specific error information related to the Body element <deatil> A human readable explanation of the fault  <faultstring> A code for identifying the fault <faultcode> Description Sub-element
SOAP HTTP Binding 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.345.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
If success :   200 OK  Content-Type: text/plain Content-Length: 200  If failure :   400 Bad Request Content-Length: 0  SOAP HTTP Binding  :  A SOAP method is an HTTP request/response that complies with the SOAP encoding rules. HTTP + XML = SOAP A SOAP request could be an HTTP POST or an HTTP GET request. The HTTP POST request specifies at least two HTTP headers:  Content-Type  and  Content-Length.
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. Example  : POST /item HTTP/1.1 Content-Type: application/soap+xml; charset=utf-8 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. Example : POST /item HTTP/1.1 Content-Type: application/soap+xml; charset=utf-8  Content-Length: 250
Problem In the example  a GetStockPrice request is sent to a server. The request has a StockName parameter, and a Price parameter will be returned in the response. The namespace for the function is defined in &quot;http://www.example.org/stock&quot; address.
SOAP Request :   POST /InStock HTTP/1.1  Host:  www.example.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: nnn  <?xml version=&quot;1.0&quot;?>  <soap:Envelope xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;>  <soap:Body xmlns:m=&quot;http://www.example.org/stock&quot;>      <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=&quot;1.0&quot;?> <soap:Envelope xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;> <soap:Body xmlns:m=&quot;http://www.example.org/stock&quot;> <m:GetStockPriceResponse>  <m:Price>34.5</m:Price> </m:GetStockPriceResponse> </soap:Body> </soap:Envelope>
Example
<?xml version=&quot;1.0&quot;?>  <soap:Envelope xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;> <soap:Header> <m:reservation xmlns:m=&quot;http://travelcompany.example.org/reservation&quot; soap:role=&quot;http://www.w3.org/2003/05/soap-envelope/role/next&quot; soap:mustUnderstand=“1&quot;> <m:reference>uuid:093a2da1-q345-739r-ba5d-pqff98fe8j7d</m:reference> <m:dateAndTime>2001-11-29T13:20:00.000-05:00</m:dateAndTime> </m:reservation> <n:passenger xmlns:n=&quot;http://mycompany.example.com/employees&quot; soap:role=&quot;http://www.w3.org/2003/05/soap-envelope/role/next&quot; soap:mustUnderstand=“1&quot;> <n:name>Niyaz ahmad rao</n:name> </n:passenger> </soap:Header> ... ... </soap:Envelope>
<soap:body> <p:itinerary xmlns:p=&quot;http://travelcompany.example.org/reservation/travel&quot;> <p:departure> <p:departing>New York</p:departing> <p:arriving>Los Angeles</p:arriving> <p:departureDate>2001-12-14</p:departureDate> <p:departureTime>late afternoon</p:departureTime> <p:seatPreference>aisle</p:seatPreference> </p:departure> <p:return> <p:departing>Los Angeles</p:departing> <p:arriving>New York</p:arriving> <p:departureDate>2001-12-20</p:departureDate> <p:departureTime>mid-morning</p:departureTime> <p:seatPreference/> </p:return> </p:itinerary> <q:lodging xmlns:q=&quot;http://travelcompany.example.org/reservation/hotels&quot;> <q:preference>none</q:preference> </q:lodging </soap:body>

More Related Content

PDF
SQL Server - Querying and Managing XML Data
PPT
Introduction to XML
PDF
Introduction to XHTML
PPTX
What is xml
PDF
XML Introduction
SQL Server - Querying and Managing XML Data
Introduction to XML
Introduction to XHTML
What is xml
XML Introduction

What's hot (20)

PPT
Xhtml
PPT
Xml 215-presentation
PDF
Web programming by Najeeb ullahAzad(1)
PPTX
Xml For Dummies Chapter 4 Adding Xhtml For The Web
PDF
Web programming unit IIII XML &DOM NOTES BY BHAVSINGH MALOTH
PPTX
Fergus Fahey - DRI/ARA(I) Training: Introduction to EAD - Introduction to XML
PDF
Vskills angular js sample material
PPT
Introduction to XML
PPT
Introduction to XML
PDF
Wp unit III
PPTX
Computer fundamentals-internet p2
PDF
Wp unit 1 (1)
PPT
Design Tools Html Xhtml
PDF
Xml tutorial
 
PDF
Web engineering notes unit 4
PPTX
PPS
Xhtml
Xml 215-presentation
Web programming by Najeeb ullahAzad(1)
Xml For Dummies Chapter 4 Adding Xhtml For The Web
Web programming unit IIII XML &DOM NOTES BY BHAVSINGH MALOTH
Fergus Fahey - DRI/ARA(I) Training: Introduction to EAD - Introduction to XML
Vskills angular js sample material
Introduction to XML
Introduction to XML
Wp unit III
Computer fundamentals-internet p2
Wp unit 1 (1)
Design Tools Html Xhtml
Xml tutorial
 
Web engineering notes unit 4
Ad

Viewers also liked (20)

PPTX
WS-Addressing
PPTX
Web Services - SOAP (part 2)
PPT
Soa Primer
PDF
[Android] Web services
ODP
Working with jpa
PPT
PDF
JPQL/ JPA Activity 2
 
PPT
15 jpaql
PPT
Web Services Part 2
PDF
JPQL/ JPA Activity 1
 
PDF
JPQL/ JPA Activity 3
 
PPT
PPT
Patni Hibernate
ODP
How to bake reactive behavior into your Java EE applications
PDF
FinelyMe-JustFit Intro
PDF
Introduction to developing modern web apps
PDF
Quickstart for continuous integration
PDF
Continuous integration practices to improve the software quality
PDF
Designing Scalable Applications
PPT
Spring Transaction
WS-Addressing
Web Services - SOAP (part 2)
Soa Primer
[Android] Web services
Working with jpa
JPQL/ JPA Activity 2
 
15 jpaql
Web Services Part 2
JPQL/ JPA Activity 1
 
JPQL/ JPA Activity 3
 
Patni Hibernate
How to bake reactive behavior into your Java EE applications
FinelyMe-JustFit Intro
Introduction to developing modern web apps
Quickstart for continuous integration
Continuous integration practices to improve the software quality
Designing Scalable Applications
Spring Transaction
Ad

Similar to Web Services Part 1 (20)

PPT
Introduction to XML
PPT
[DSBW Spring 2010] Unit 10: XML and Web And beyond
PPTX
PPTX
Week1 xml
PPT
Intro XML for archivists (2011)
PPT
PPT
01 Xml Begin
PPTX
Xml For Dummies Chapter 8 Understanding And Using Dt Ds it-slideshares.blog...
DOCX
Xml material
DOCX
Xml material
DOCX
Xml material
PPTX
web design technology- mark up languages
PDF
3.web Technology and sub topics for computer applications
PPT
Xml description
PPT
O9xml
PPT
Chen's first test slides
PPT
Chen test paper20abcdeftfdfd
PPT
Test for an issue
DOCX
Xml 150323102007-conversion-gate01
Introduction to XML
[DSBW Spring 2010] Unit 10: XML and Web And beyond
Week1 xml
Intro XML for archivists (2011)
01 Xml Begin
Xml For Dummies Chapter 8 Understanding And Using Dt Ds it-slideshares.blog...
Xml material
Xml material
Xml material
web design technology- mark up languages
3.web Technology and sub topics for computer applications
Xml description
O9xml
Chen's first test slides
Chen test paper20abcdeftfdfd
Test for an issue
Xml 150323102007-conversion-gate01

More from patinijava (14)

PPT
Struts N E W
PPT
Session Management
PPT
S E R V L E T S
PPS
Struts Java I I Lecture 8
PPT
Servlet Api
PPT
Servlet11
PPT
Sping Slide 6
PPT
Entity Manager
PPT
PPT
PPT
Webbasics
PPT
Internetbasics
PPT
PPT
Portlet
Struts N E W
Session Management
S E R V L E T S
Struts Java I I Lecture 8
Servlet Api
Servlet11
Sping Slide 6
Entity Manager
Webbasics
Internetbasics
Portlet

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Cloud computing and distributed systems.
PDF
cuic standard and advanced reporting.pdf
PDF
Approach and Philosophy of On baking technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Big Data Technologies - Introduction.pptx
The AUB Centre for AI in Media Proposal.docx
Chapter 3 Spatial Domain Image Processing.pdf
Spectral efficient network and resource selection model in 5G networks
Understanding_Digital_Forensics_Presentation.pptx
Cloud computing and distributed systems.
cuic standard and advanced reporting.pdf
Approach and Philosophy of On baking technology
“AI and Expert System Decision Support & Business Intelligence Systems”
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
MIND Revenue Release Quarter 2 2025 Press Release
Dropbox Q2 2025 Financial Results & Investor Presentation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Mobile App Security Testing_ A Comprehensive Guide.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Unlocking AI with Model Context Protocol (MCP)
The Rise and Fall of 3GPP – Time for a Sabbatical?

Web Services Part 1

  • 2. INTRODUCTION The root of WEB-SERVICES can be traced out when the concept of component architecture began taking shape. Beauty of Component architecture is develop on one platform and run in different platform Distributed Computing RMI CORBA COM WEB-BASED Application JSP SERVLET
  • 3. WEB-SERVICES as named suggest service available on the web. This network may be LAN,WAN,MAN or Internet IBM says : internet based modular application that perform a specific business task and confirm to a specific technical format A practical example of a web-services is one company calling services of other company to directly pass on a purchase order through internet connection
  • 4. Characteristics of WEB-SERVICES A web-services can be accessed over the WEB The service interface helps the web-services to be called any other programme or services. The service interface is an XML document since XML has emerged as the global data exchange technology A web-services can be registered in a service registry to be accessed by other programme Web-services use the standers Web protocol to communicate
  • 5. Life Cycle of Web-services A web-service needs to be created The service interface and invocation method should be defined The web-service should be published on the internet or intranet to facilitate the web user in using the service The web user should be able to find the web-service The web-service should be invoked The web-service should be unpublished when no longer in use.
  • 6. Requirement for creating a web-services Representing data in a standard format : XML is emerged as standers way to represent data. A common extensible message format : A simple Object access protocol ( SOAP ) is a light weight protocol for exchange information. A common extensible, service descripting language : A web services description language ( WSDL ) is used to document the same for Web-services. A list of service providers and the services offered by them : Universal Description Discovery and integration ( UDDI ) is a industry initiated project, which satisfying the requirement of maintaining registries.
  • 7. Working of the Web-services A web-service consist a file which contain either a class providing a functionality of web-services or reference of the external class. This information is an XML file known as WSDL file. Depending on the requirments, the client invokes the web method of the service and send and receive the parameter from the method. The server then returns the appropriate result to the client
  • 8. Web-services which run over the HTTP can be accessed by following ways: HTTP GET: HTTP POST : SOAP : Soap messaging is the proper way to call a web-services. The Get and Post method is are useful if a web-services is to be called quickly and no soap client is available. These operation will support simple inputs and outputs. SOAP is used whenever there exist a need to pass complex objects and data
  • 9. Advantages of Web-services Cross buisness integration Improved efficiency Closer customer relationships Facilitates just-in-time relationships Reduce complexity Disadvantages: Network Security risk XML support is necessary Cost of deploying is high
  • 11. What is XML? XML stands for E X tensible M arkup L anguage XML is a markup language much like HTML. XML was designed to describe data . XML tags are not predefined in XML. You must define your own tags . XML is self describing . XML uses a DTD ( Document Type Definition ) to formally describe the data.
  • 12. Difference between XML and HTML XML is not a replacement for HTML. XML and HTML were designed with different goals : XML was designed to describe data and to focus on what data is . HTML was designed to display data and to focus on how data looks . HTML is about displaying information, XML is about describing information.
  • 13. XML is eXtensible : The tags used to markup HTML documents and the structure of HTML documents are predefined . The author of HTML documents can only use tags that are defined in the HTML standard . XML allows the author to define his own tags and his own document structure. It is important to understand that XML is not a replacement for HTML . In the future development of the Web it is most likely that XML will be used to structure and describe the Web data, while HTML will be used to format and display the same data.
  • 14. How can XML be used? XML can keep data separated from your HTML XML can be used to store data inside HTML documents XML can be used as a format to exchange information XML can be used to store data in files or in databases
  • 15. XML Syntax <?xml version=&quot;1.0&quot;?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> The first line in the document: The XML declaration should always be included. It defines the XML version of the document. The next line defines the first element of the document (the root element The next lines defines 4 child elements of the root (to, from, heading, and body):
  • 16. All XML elements must have a closing tag XML tags are case sensitive All XML elements must be properly nested All XML documents must have a root tag Attribute values must always be quoted <?xml version=&quot;1.0&quot;?> <note date=&quot;12/11/99&quot;> …………… </note>
  • 17. XML Attributes XML attributes are normally used to describe XML elements, or to provide additional information about elements <?xml version=&quot;1.0&quot;?> <note date=&quot;12/11/99&quot;> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
  • 18. Using an Attribute for sex: <person sex=&quot;female&quot;> <firstname>Anna</firstname> <lastname>Smith</lastname> </person> Using an Element for sex: <person> <sex>female</sex> <firstname>Anna</firstname> <lastname>Smith</lastname> </person>
  • 19. There are no fixed rules about when to use attributes to describe data, and when to use elements. Attributes are handy in HTML, but in XML you should try to avoid them , as long as the same information can be expressed using elements. Problems with attributes : attributes can not contain multiple values (elements can) attributes are not expandable (for future changes) attributes can not describe structures (like child elements can) attributes are more difficult to manipulate by program code attribute values are not easy to test against a DTD
  • 20. XML Validation A &quot;Well Formed&quot; XML document is a document that conforms to the XML syntax rules that we described earlier. A &quot;Valid&quot; XML document is a &quot;Well Formed&quot; XML document which conforms to the rules of a Document Type Definition (DTD). The following is the same document as above but with an added reference to a DTD: <?xml version=&quot;1.0&quot;?> <!DOCTYPE note SYSTEM &quot;InternalNote.dtd&quot;> <note> <to>Tove</to> …………… </note>
  • 21. XML DTD - An Introduction to XML Document Type Definitions The purpose of a DTD is to define the legal building blocks of an XML document. It defines the document structure with a list of legal elements. Internal DTD External DTD Use of DTD : XML provides an application independent way of sharing data. With a DTD, independent groups of people can agree to use a common DTD for interchanging data. Your application can use a standard DTD to verify that data that you receive from the outside world is valid. You can also use a DTD to verify your own data.
  • 22. Internal DTD <?xml version=&quot;1.0&quot;?> <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
  • 23. External DTD <?xml version=&quot;1.0&quot;?> <!DOCTYPE note SYSTEM &quot;note.dtd&quot;> <note> …………… .. </note> <?xml version=&quot;1.0&quot;?> <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>
  • 24. DTD - XML building blocks XML documents (and HTML documents) are made up by the following building blocks: Elements : Elements are the main building blocks of both XML and HTML documents. Tags : Tags are used to markup elements. A starting tag like <element_name> mark up the beginning of an element, and an ending tag like </element_name> mark up the end of  an element Attributes : Attributes provide extra information about elements. .
  • 25. PCDATA : PCDATA means parsed character data.Think of character data as the text found between the start tag and the end tag of an XML element.PCDATA is text that will be parsed by a parser. Tags inside the text will be treated as markup and entities will be expanded.  CDATA : CDATA also means character data.CDATA is text that will NOT be parsed by a parser. Tags inside the text will NOT be treated as markup and entities will not be expanded Entities : Most of you will known the HTML entity reference: &quot;&nbsp;&quot;  that is used to insert an extra space in an HTML document. Entities are expanded when a document is parsed by an XML parser.
  • 26. Declaring an Element <!ELEMENT element-name (element-content)> Empty Tag : <!ELEMENT img (EMPTY)> Elements with data : <!ELEMENT note (#PCDATA)> Elements with children (sequences) : <!ELEMENT note (to,from,heading,body)> Declares that the child element message can only occur one time inside the note element : <!ELEMENT note (message)>
  • 27. The + sign declares that the child element message must occur one or more times inside the note element : <!ELEMENT note (message+)> The * sign declares that the child element message can occur zero or more times inside the note element <!ELEMENT note (message*)> The ? sign declares that the child element message can occur zero or one times inside the note element. <!ELEMENT note (message?)> Define This : <!ELEMENT note (to+,from,header,message*,#PCDATA)>
  • 28. Declaring Attributes <!ATTLIST element-name attribute-name attribute-type default-value> Attribute-type : CDATA :The value is character data ID : The value is an unique id IDREF : The value is the id of another element ENTITY : The value is an entity Xml : The value is predefined
  • 29. attribute-default-value #DEFAULT value : The attribute has a default value #REQUIRED : The attribute value must be included in the element #IMPLIED : The attribute does not have to be included #FIXED value : The attribute value is fixed XML example: <square width=&quot;100&quot;></square> DTD example: <!ELEMENT square EMPTY> <!ATTLIST square width CDATA &quot;0&quot;>
  • 30. XML NAMESPACE XML Namespaces provide a method to avoid element name conflicts In XML, element names are defined by the developer. This often results in a conflict when trying to mix XML documents from different XML applications
  • 31. This XML carries HTML table information: <table> <tr> <td>Apples</td> <td>Bananas</td> </tr> </table> This XML carries information about a table (a piece of furniture): <table> <name>African Coffee Table</name> <width>80</width> <length>120</length> </table>
  • 32. If these XML fragments were added together, there would be a name conflict. Both contain a <table> element, but the elements have different content and meaning. An XML parser will not know how to handle these differences XML Namespaces - The xmlns Attribute When using prefixes in XML, a so-called namespace for the prefix must be defined. The namespace is defined by the xmlns attribute in the start tag of an element. The namespace declaration has the following syntax. xmlns: prefix =&quot; URI &quot;.
  • 33. <root> <h:table xmlns:h=&quot;http://www.w3.org/TR/html4/&quot;> <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table> <f:table xmlns:f=&quot;http://www.w3schools.com/furniture&quot;> <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> </root> In the example above, the xmlns attribute in the <table> tag give the h: and f: prefixes a qualified namespace When a namespace is defined for an element, all child elements with the same prefix are associated with the same namespace.
  • 34. XML SCHEMA The purpose of an XML Schema is to define the legal building blocks of an XML document, just like a DTD. An XML Schema: defines elements that can appear in a document defines attributes that can appear in a document defines which elements are child elements defines the order of child elements defines the number of child elements defines whether an element is empty or can include text defines data types for elements and attributes defines default and fixed values for elements and attributes
  • 35. We think that very soon XML Schemas will be used in most Web applications as a replacement for DTDs. Here are some reasons: XML Schemas are extensible to future additions XML Schemas are richer and more powerful than DTDs XML Schemas are written in XML XML Schemas support data types. XML Schemas support namespaces
  • 36. XML Schemas Support Data Types One of the greatest strength of XML Schemas is the support for data types.With support for data types : It is easier to describe allowable document content It is easier to validate the correctness of data It is easier to work with data from a database It is easier to define data facets (restrictions on data) It is easier to define data patterns (data formats) It is easier to convert data between different data types
  • 37. XML Schemas use XML Syntax You don't have to learn a new language You can use your XML editor to edit your Schema files You can use your XML parser to parse your Schema files You can manipulate your Schema with the XML DOM You can transform your Schema with XSLT
  • 38. XML Schemas Secure Data Communication With XML Schemas, the sender can describe the data in a way that the receiver will understand. A date like: &quot;03-11-2004&quot; will, in some countries, be interpreted as 3.November and in other countries as 11.March.However, an XML element with a data type like this: <date type=&quot;date&quot;>2004-03-11</date> ensures a mutual understanding of the content, because the XML data type &quot;date&quot; requires the format &quot;YYYY-MM-DD&quot;.
  • 39. A Simple XML Document (note.xml) <?xml version=&quot;1.0&quot;?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
  • 40. A DTD File (note.dtd) <!ELEMENT note (to, from, heading, body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> The first line defines the note element to have four child elements: &quot;to, from, heading, body&quot;.
  • 41. An XML Schema (note.xsd) <?xml version=&quot;1.0&quot;?> <xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; targetNamespace=&quot;http://www.w3schools.com&quot; xmlns=&quot;http://www.w3schools.com&quot; elementFormDefault=&quot;qualified&quot;> <xs:element name=&quot;note&quot;> <xs:complexType> <xs:sequence> <xs:element name=&quot;to&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;from&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;heading&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;body&quot; type=&quot;xs:string&quot;/> </xs:sequence> </xs:complexType> </xs:element></xs:schema>
  • 42. <?xml version=&quot;1.0&quot;?> 1.<xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; 2.targetNamespace=&quot;http://www.w3schools.com&quot; 3.xmlns=&quot;http://www.w3schools.com&quot; 4.elementFormDefault=&quot;qualified&quot;> ............................................ </xs:schema> 1.indicates that the elements and data types used in the schema come from the &quot;http://www.w3.org/2001/XMLSchema&quot; namespace 2.indicates that the elements defined by this schema (note, to, from, heading, body.) come from the &quot;http://www.w3schools.com&quot; namespace 3.indicates that the default namespace is &quot;http://www.w3schools.com&quot;. 4.indicates that any elements used by the XML instance document which were declared in this schema must be namespace qualified .
  • 43. DTD reference in XML : <?xml version=&quot;1.0&quot;?> <!DOCTYPE note SYSTEM &quot;http://www.w3schools.com/dtd/note.dtd&quot;> <note> ……… .…................... </note> Schema reference in XML : <?xml version=&quot;1.0&quot;?> <note xmlns=&quot;http://www.w3schools.com&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://www.w3schools.com note.xsd&quot;> ……………………………… </note>
  • 44. <?xml version=&quot;1.0&quot;?> <note xmlns=&quot;http://www.w3schools.com&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://www.w3schools.com note.xsd&quot;> ………………………… .. </note> specifies the default namespace declaration Once you have the XML Schema Instance namespace available : xmlns:xsi= http://www.w3.org/2001/XMLSchema-instance you can use the schemaLocation attribute. This attribute has two values. The first value is the namespace to use. The second value is the location of the XML schema to use for that namespace : xsi:schemaLocation=&quot;http://www.w3schools.com note.xsd&quot;
  • 45. Style Sheet <?xml version=&quot;1.0&quot; encoding=&quot;ISO8859-1&quot; ?> <?xml:stylesheet href=&quot;cd_catalog.css&quot; type=&quot;text/css&quot;?> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> ……… .. </CD>
  • 46. <HTML> <BODY>CATALOG { width: 100%; } CD { display: block; margin-bottom: 30pt; margin-left: 0; } TITLE { color: blue; font-size: 20pt; } ARTIST { color: green; font-size: 20pt; } COUNTRY,PRICE,YEAR,COMPANY { Display: block; color: red; margin-left: 20pt; }</BODY></HTML>
  • 47. XSLT XSLT stands for XSL Transformations. It is use to transform XML documents into other formats, like XHTML. XSL : XSL stands for EXtensible Stylesheet Language. XSLT stands for XSL Transformations XSLT is the most important part of XSL XSLT transforms an XML document into another XML document XSLT uses XPath to navigate in XML documents XSLT is a W3C Recommendation
  • 48. Catalog.xml : <?xml version=&quot;1.0&quot; ?> <?xml:stylesheet href=&quot;catalog.xsl&quot; type=&quot;text/xsl&quot;?> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> ………… .
  • 49. catalog.xsl : <?xml version='1.0'?> <xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/TR/WD-xsl&quot;> <xsl:template match=&quot;/&quot;> <html> <body> <table border=&quot;2&quot; bgcolor=&quot;yellow&quot;> <tr> <th>Title</th> <th>Artist</th> </tr> <xsl:for-each select=&quot;CATALOG/CD&quot;> <tr> <td><xsl:value-of select=&quot;TITLE&quot;/></td> <td><xsl:value-of select=&quot;ARTIST&quot;/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
  • 50. The match attribute is used to associate a template with an XML element . match=&quot;/&quot; defines the whole document. The <xsl:value-of> element can be used to extract the value of an XML element and add it to the output stream of the transformation The XSL <xsl:for-each> element can be used to select every XML element of a specified node-set <xsl:for-each select=&quot;catalog/cd[artist='Bob Dylan']&quot;> Legal filter operators are: =  (equal) != (not equal) &lt; less than &gt; greater than
  • 51. To sort the output, simply add an <xsl:sort> element inside the <xsl:for-each> element in the XSL file: <?xml version='1.0'?> ………………… . <xsl:for-each select=&quot;catalog/cd&quot;> <xsl:sort select=&quot;artist&quot;/> <tr> <td><xsl:value-of select=&quot;title&quot;/></td> <td><xsl:value-of select=&quot;artist&quot;/></td> </tr> </xsl:for-each> …………………………………… . </xsl:stylesheet>
  • 52. To add a conditional test, add the <xsl:if> element inside the <xsl:for-each> element in the XSL file: <?xml version='1.0'?> ………………… . <xsl:for-each select=&quot;catalog/cd&quot;> <xsl:if test=&quot;price &gt; 10&quot;> <tr> <td><xsl:value-of select=&quot;title&quot;/></td> <td><xsl:value-of select=&quot;artist&quot;/></td> </tr> </xsl:if> </xsl:for-each> …………………………………… . </xsl:stylesheet
  • 53. To insert a multiple conditional test against the XML file, add the <xsl:choose>, <xsl:when>, and <xsl:otherwise> elements to the XSL file: <xsl:for-each select=&quot;catalog/cd&quot;> <tr> <td><xsl:value-of select=&quot;title&quot;/></td> <xsl:choose> <xsl:when test=&quot;price &gt; 10&quot;> <td bgcolor=&quot;#ff00ff&quot;> <xsl:value-of select=&quot;artist&quot;/> </td> </xsl:when> <xsl:otherwise> <td><xsl:value-of select=&quot;artist&quot;/></td> </xsl:otherwise> </xsl:choose> </tr> </xsl:for-each>
  • 54. Simple object Access protocol (SOAP 1.2)
  • 55. Introduction SOAP is a lightweight protocol intended for exchanging structured information in a decentralized, distributed environment SOAP uses XML technologies to define an extensible messaging framework providing a message construct that can be exchanged over a variety of underlying protocols The framework has been designed to be independent of any particular programming model and other implementation specific semantics Wire protocol similar to : IIOP for CORBA JRMP for RMI Supports XML-based RPC (Remote Procedure Call)
  • 56. 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 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 will be developed as a W3C standard
  • 57. WHAT SOAP IS NOT ? Not a component model So it will not replace objects and components, i.e. EJB™, JavaBeans™ Not a programming language So it will not replace Java Not a solution for all So it will not replace other distributed computing technologies such as RMI
  • 58. SOAP Message structure SOAP Envelope SOAP Header Header Entry Header Entry SOAP Body Body Entry Body Entry
  • 59. A SOAP message is an ordinary XML document containing the following elements: A required Envelope element that identifies the XML document as a SOAP message An optional Header element that contains header information A required Body element that contains call and response information An optional Fault element that provides information about errors that occurred while processing the message 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
  • 60. <?xml version=&quot;1.0&quot;?> <soap:Envelope xmlns:soap =&quot;http://www.w3.org/2001/12/soap-envelope &quot; soap:encodingStyle=&quot; http://www.w3.org/2001/12/soap-encoding &quot;> <soap:Header> ... ... </soap:Header> <soap:Body> ... ... <soap:Fault> ... ... </soap:Fault> </soap:Body> </soap:Envelope>
  • 61. The SOAP Envelope Element The required SOAP Envelope element is the root element of a SOAP message. It defines the XML document as a SOAP message. The SOAP encodingStyle attribute is used to define the data types used in the document. This attribute may appear on any SOAP element, and it will apply to that element's contents and all child elements. A SOAP message has no default encoding.
  • 62. SOAP Header 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 SOAP defines three attributes in the default namespace (&quot;http://www.w3.org/2001/12/soap-envelope&quot;). These attributes are: actor , mustUnderstand , and encodingStyle . The attributes defined in the SOAP Header defines how a recipient should process the SOAP message
  • 63. Actor attribute : A SOAP message may travel from a sender to a receiver by passing different endpoints along the message path. Syntax : soap:actor= “uri” <?xml version=&quot;1.0&quot;?> <soap:Envelope xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;> <soap:Header> <m:Trans xmlns:m=&quot;http://www.w3schools.com/transaction/&quot; soap:actor=&quot;http://www.w3schools.com/appml /&quot;> 234 </m:Trans> </soap:Header> ... ... </soap:Envelope> The example above contains a header with a &quot;Trans&quot; element
  • 64. 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 &quot;mustUnderstand=&quot;1&quot; to a child element of the Header element it indicates that the receiver processing the Header must recognize the element. Syntax : soap:mustUnderstand=&quot;0|1&quot; <?xml version=&quot;1.0&quot;?> <soap:Envelope xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;> <soap:Header> <m:Trans xmlns:m=&quot;http://www.w3schools.com/transaction/&quot; soap:mustUnderstand=&quot;1&quot;> 234 </m:Trans> </soap:Header> ... ... </soap:Envelope>
  • 65. SOAP Body The required SOAP Body element contains the actual SOAP message SOAP defines one element inside the Body element in the default namespace (&quot;http://www.w3.org/2001/12/soap-envelope&quot;). This is the SOAP Fault element, which is used to indicate error messages.
  • 66. <?xml version=&quot;1.0&quot;?> <soap:Envelope xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;> <soap:Body> <m:GetPrice xmlns:m=&quot;http://www.w3schools.com/prices&quot;> <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 standard.
  • 67. A SOAP response looks like this : <?xml version=&quot;1.0&quot;?> <soap:Envelope xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;> <soap:Body> <m:GetPriceResponse xmlns:m=&quot;http://www.w3schools.com/prices&quot;> <m:Price>1.90</m:Price> </m:GetPriceResponse> </soap:Body> </soap:Envelope>
  • 68. SOAP Fault Element An error message from a SOAP message is carried inside a Fault element. If a Fault element is present, it must appear as a child element of the Body element. A Fault element can only appear once in a SOAP message. Information about who caused the fault to happen <faultactor> Holds application specific error information related to the Body element <deatil> A human readable explanation of the fault <faultstring> A code for identifying the fault <faultcode> Description Sub-element
  • 69. SOAP HTTP Binding 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.345.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
  • 70. If success : 200 OK Content-Type: text/plain Content-Length: 200 If failure : 400 Bad Request Content-Length: 0 SOAP HTTP Binding : A SOAP method is an HTTP request/response that complies with the SOAP encoding rules. HTTP + XML = SOAP A SOAP request could be an HTTP POST or an HTTP GET request. The HTTP POST request specifies at least two HTTP headers: Content-Type and Content-Length.
  • 71. 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. Example : POST /item HTTP/1.1 Content-Type: application/soap+xml; charset=utf-8 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. Example : POST /item HTTP/1.1 Content-Type: application/soap+xml; charset=utf-8 Content-Length: 250
  • 72. Problem In the example a GetStockPrice request is sent to a server. The request has a StockName parameter, and a Price parameter will be returned in the response. The namespace for the function is defined in &quot;http://www.example.org/stock&quot; address.
  • 73. SOAP Request : POST /InStock HTTP/1.1 Host: www.example.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: nnn <?xml version=&quot;1.0&quot;?> <soap:Envelope xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;> <soap:Body xmlns:m=&quot;http://www.example.org/stock&quot;>     <m:GetStockPrice> <m:StockName>IBM</m:StockName>      </m:GetStockPrice> </soap:Body> </soap:Envelope>
  • 74. SOAP Response: HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: nnn <?xml version=&quot;1.0&quot;?> <soap:Envelope xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;> <soap:Body xmlns:m=&quot;http://www.example.org/stock&quot;> <m:GetStockPriceResponse> <m:Price>34.5</m:Price> </m:GetStockPriceResponse> </soap:Body> </soap:Envelope>
  • 76. <?xml version=&quot;1.0&quot;?> <soap:Envelope xmlns:soap=&quot;http://www.w3.org/2001/12/soap-envelope&quot; soap:encodingStyle=&quot;http://www.w3.org/2001/12/soap-encoding&quot;> <soap:Header> <m:reservation xmlns:m=&quot;http://travelcompany.example.org/reservation&quot; soap:role=&quot;http://www.w3.org/2003/05/soap-envelope/role/next&quot; soap:mustUnderstand=“1&quot;> <m:reference>uuid:093a2da1-q345-739r-ba5d-pqff98fe8j7d</m:reference> <m:dateAndTime>2001-11-29T13:20:00.000-05:00</m:dateAndTime> </m:reservation> <n:passenger xmlns:n=&quot;http://mycompany.example.com/employees&quot; soap:role=&quot;http://www.w3.org/2003/05/soap-envelope/role/next&quot; soap:mustUnderstand=“1&quot;> <n:name>Niyaz ahmad rao</n:name> </n:passenger> </soap:Header> ... ... </soap:Envelope>
  • 77. <soap:body> <p:itinerary xmlns:p=&quot;http://travelcompany.example.org/reservation/travel&quot;> <p:departure> <p:departing>New York</p:departing> <p:arriving>Los Angeles</p:arriving> <p:departureDate>2001-12-14</p:departureDate> <p:departureTime>late afternoon</p:departureTime> <p:seatPreference>aisle</p:seatPreference> </p:departure> <p:return> <p:departing>Los Angeles</p:departing> <p:arriving>New York</p:arriving> <p:departureDate>2001-12-20</p:departureDate> <p:departureTime>mid-morning</p:departureTime> <p:seatPreference/> </p:return> </p:itinerary> <q:lodging xmlns:q=&quot;http://travelcompany.example.org/reservation/hotels&quot;> <q:preference>none</q:preference> </q:lodging </soap:body>