What Is Webservice
What Is Webservice
What Is Webservice
identifies the parts and how they relate to each other. More specifically, a markup language is a set
of symbols that can be placed in the text of a document to demarcate and label the parts of that
document.
What is Webservice:
Advantages:
Interoperability:
Loose coupling. Webservices enable loose coupling. (A using webservice from B, can switch to C –
with minimal changes to code--)
Mashup applications: An application can use more than one web-service (from different
applications) to create one piece of functionality.
e.g. Project report application can provide a web-service with Project status details. This can be
combined with webservice from Google Maps that shows actual status on ground. These two details
from the two webservices can be used to generate “actual status report and validity of project
report”
SOAP:
These use XML based SOAP protocol for messaging. (that uses HTTP POST)
SOAP can also use other protocols like SMTP, or directly with TCP.
RESTFul:
Supports multiple data formats: This can use not only XML, but any other format. (mostly used
formats are JSON, XML, Text)
Webservice Standards
Each language & platform has standards for implementing the 2 types of web-services (SOAP &
Restful). (Also, these languages provide tools to implement the webservices)
SOA
What is SOA:
o SOA is collection of architectural principles, Design in such a way that an application is
composed of several S/W services with well defined interfaces and can communicate with
each in loosely coupled manner.
Who:
o W3C & OASIS are standards bodies, who comes up with architectural principles for SOA.
o (W3C & OASIS are formed by orgs like Microsoft, Oracle, IBM etc)
o SOA also has two roles: Provider & Consumer.
What is Service:
Advantages:
o Platform Independency: (as in web-service above)
o Focussed Developer roles: (focussed on specific Domain)
o Loosely Coupled: (i.e. Replacing a service with a different implementation, without changing
the code)
o Reusability of a service:
o Cost Reduction: (Due to reusability & reduction of complexity)
o Scalability:
o Availability: As we deploy the service on multiple instances, it is highly available (even if a
few instances go down)
XML
What is XML:
o Extensible Mark-up Language: We can create our own mark-up for a specific
context/domain/purpose.
o HTML has predefined set of elements <b> & </b> (e.g. <b> …. </b> These elements
indicates that text between these elements is to be in bold)
o In XML, we can define our own mark-up elements.
e.g. For e-commerce application, we can create mark-up element “Order-ML” that can
have nested elements “Order-ID, Line-Items, Shipping-Address” etc.
Applications can use this XML to show the data to users, exchange this info with
others, manipulate the data.
o XML has both data & metadata, custom elements,
..
..
</RootElement> closing of Root element.
(OR) element can be defined without child elements using <element-name attribute=val … />
Why XML:
o This can be specific to the domain/business purpose.
o We have both Data & Metadata.
XML Syntax:
o XML has well-formedness rules (so that XML can be understood & used across applications,
users). This well-formedness is verified by XML parser.
XML is said to be well-formed, if it follows the below XML syntax rules:
(Refer to the XML tree structure above)
1. XML document is formed as “Tree of elements” with only 1 root element per
document.
2. Start of an element is indicated by < elementName
3. Closing of an element is indicated by </ elementName>
XML is case sensitive. Element names starts with letter or _, can’t start with letters
xml, ?, and barred symbols( in rule 9)
XML elements can be extended to have more info. (This will not impact existing
applications using the XML)
But removing elements can break an application.
4. Content for the element is given between start and closing tag.
5. Elements in the content part of an element are its child elements.
6. Branches to the root are child elements.
7. Any element can have sub-elements (child elements).
8. Any element can have 1 or more attributes with respective values (as key value pairs).
Values should be enclosed in single/double quotes.
Attributes can’t have multiple values, tree structures, be expanded.
9. Body of element can’t have <, > ,“ , ‘, &
Hence, use below left-column to represent the barred symbols in the body of the
element.
10. <!-- This is a comment --> (Comment text should not have --)
11. White spaces are preserved in XML i.e. Multiple white spaces are not reduced to 1
white-space. (unlike in HTML)
12. XML Prologue: <?xml version="1.0" encoding="UTF-8"?>
Prologue is optional. If given, it should be the 1st line of XML document.
It will not have closing tag.
o XML also has validation rules, which can be defined and verified using pre-defined XML
Schema (XSD)
Purpose of XML: This is used mainly for three purposes in software applications
1. As a Configuration File
This has configuration data (with elements defining the configuration elements)
e.g. Apache CXF is a web-service engine uses Spring configuration (XML file).
e.g. SOAP & REST use XML file data exchange. (RPC can use XML data)
XML Name-Spaces:
This is to uniquely qualify an XML element by allowing multiple elements to be used with same
name in an XML document.
This allows usage of elements from different XSDs in a single XML document.
Element names in a namespace should be unique. (so that element names can repeat across
namespaces)
o This is similar to Package (A package will have only 1 class or Interface with that name)
Default Namespace is given by XMLNS=”URI”
In XSD we define the namespaces using a global unique identifier – URI- for that namespace.
(as it needs to be global unique id, we generally use URL) else there can be conflict later.
o XML Parser will not look up at the contents of URI to get namespace details, but only use
it as unique identifier for the namespace.
URL is the most common URI.
URN-Unique Resource Name as another URI.
e.g. http://www.xyz.com/order
Instead of using the long URL for namespace, we use a prefix. (e.g. below)
XMLNS:amz = “http://www.xyz.com/order“
XMLNS is element name by W3C for XML-namespace in XSD. “amz“ is the prefix for
namespace.
Namespaces & prefix can be defined as attribute of root element or any nested element.
XML can be defined from template, or XSD file, or from DTD file.
<?xml version="1.0" encoding="UTF-8"?>
<tns:patient xmlns:tns="http://www.ws.com/Patients"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.ws.com/Patients XSDs/Patients.xsd ">
<tns:id>0</tns:id>
<tns:name>tns:name</tns:name>
<tns:age>0</tns:age>
<tns:dob>2001-01-01</tns:dob>
<tns:email>tns:email</tns:email>
<tns:id>0</tns:id>
</tns:patient>
Example of Restrictions:
<simpleType name="ID">
<restriction base="int">
<pattern value="[0-9]*"></pattern>
</restriction>
</simpleType>
Sequence: used to list order of elements in order in which the elements are
defined between “sequence” tags.
Choice: only 1 of the elements can be selected.
All: all elements between “all” tags are to be used.
Advantages:
o Platform Independence: This comes from http(which is transport independent) and
XML(data/structure independent)
o For providing & consuming service to & from legacy applications.
e.g. Airline reservation system(where user interface is tightly coupled
with business logic). Now to allow online check-in, we can expose
business logic in legacy system as a webservice and make our application
talk to this webservice. (If we want to enable mobile application, we
can consume the same webservice)
o Webservices opens New Revenue & Profit Channels:
Instead of selling complete CRM application, Oracle exposed required
webservices and charged its customers only for the webservices consumed.
o Webservices can be exposed through firewalls.
Disadvantages:
o Ambiguous standards due to different bodies like W3C, OASIS, etc.
o Performance impact to serialization & deserialization of SOAP messages.
As, every time XML has to be converted to & from language specific
objects.