Upload
jordan-hampton
View
223
Download
0
Tags:
Embed Size (px)
Citation preview
Advanced Web-based Systems | Misbhauddin
Web ServicesXML-RPC, SOAP, REST
Advanced Web-based Systems | Misbhauddin
PHP ScenarioWeb Server
HTTP Request
HTTP ResponseClient
exec w/environ
html
PHPCompiler
SQL
Database
SAME AS CGI
<?php $con = mysqli_connect($host, $user, $pwd, $db); $query = “SELECT name FROM user”; $result = mysqli_query($con,$query); $name = mysqli_fetch_array($result)[0];?><html><head><title>Test PHP Page</title></head><body> <h1>Welcome Mr. <?php echo $name; ?></h1>…….
Presentation+
Business Logic+
Data (SQL)=
All messed up
Advanced Web-based Systems | Misbhauddin
RIA Scenario
Web Server
XMLHTTP Request
XML Response
Browser
QUERY_STRING
XMLData
Server-Side Technology
SQL
Database
JavaScript
Update (HTML)
Presentation&
Visualization
BusinessLogic
Data &Models
Components of Data ExchangeTwo applications want to share data over the Internet• Initiating Action: Things don’t happen without any reason. A triggering
mechanism is needed.• Automatic: started at a fixed time (chron job, feed exchange)• User Initiated: form submission
• Data Format: Data needs to be stored and transferred in a format understood by both applications.
• Data Transfer Mechanism: Process to transfer the data over the internet
Advanced Web-based Systems | Misbhauddin
Data Transfer Mechanism• Selecting a proper protocol and data interchange format to pass data between
your app is one of the most important decisions to make during the development process• Common and widely used protocols• XML-RPC• SOAP• REST
• All of these protocols transport data over the HTTP protocol• XML-RPC & SOAP are XML-based• REST works both with JSON or XML
Advanced Web-based Systems | Misbhauddin
Advanced Web-based Systems | Misbhauddin
Web Services
• Web services are web application components• Unlike traditional client / server model (web server / web page system)• Does not provide user with a GUI• Share business logic, data and processes through a programmatic interface
across a network• The applications interface, not the users
Client / Server Web Services
Advanced Web-based Systems | Misbhauddin
Web Services
• Allow different applications from different sources to communicate with each other• Are not tied to any one operating system or programming language• Do not require the use of browsers or HTML• Web services are sometimes called application services
Advanced Web-based Systems | Misbhauddin
XML-RPC
• A set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet• Remote procedure calling using HTTP as the transport and XML as the encoding
<methodCall> <methodName>sample.sumAndDifference</methodName> <params> <param><value><int>5</int></value></param> <param><value><int>3</int></value></param> </params></methodCall>
Advanced Web-based Systems | Misbhauddin
Simple Object Access Protocol (SOAP)• SOAP relies exclusively on XML to provide messaging services• The XML used to make requests and receive responses in SOAP can become
extremely complex• Technologies in SOAP
• WSDL - Web Services Description Language• UDDI - Universal Description, Discovery and Integration
SOAP
Advanced Web-based Systems | Misbhauddin
• Messaging protocol that allows programs that run on different operating systems
• Communicate using HTTP & XML
• Specifies how to encode HTTP Header and XML Data
Advanced Web-based Systems | Misbhauddin
WSDL
• It is written in XML• It is an XML document• It is used to describe Web services• It is also used to locate Web services
<definitions> <types> data type definitions........ </types>
<message> definition of the data being communicated.... </message>
<portType> set of operations...... </portType>
<binding> protocol and data format specification.... </binding></definitions>
Advanced Web-based Systems | Misbhauddin
WSDL<message name="getTermRequest"> <part name="term" type="xs:string"/></message>
<message name="getTermResponse"> <part name="value" type="xs:string"/></message>
<portType name="glossaryTerms"> <operation name="getTerm"> <input message="getTermRequest"/> <output message="getTermResponse"/> </operation></portType>
glossaryTerms is a function library, "getTerm" is a function with "getTermRequest" as the input parameter, and getTermResponse as the return parameter
UDDI• Is a directory service where businesses can register and search for Web services• Discover the right business from the millions currently online• Reaching new customers and increasing access to current customers• Solving customer-driven need to remove barriers • Describing services and business processes programmatically in a single, open,
and secure environment
Advanced Web-based Systems | Misbhauddin
Saudi Airlines
Fly Dubai
Ticket Rate
Register
Register
Travel AgenciesFind Airline Interface
UDDI
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
Advanced Web-based Systems | Misbhauddin
<?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> ... </soap:Header> <soap:Body> ... <soap:Fault> ... </soap:Fault> </soap:Body></soap:Envelope>
SOAP Envelope Element• It is a required element• It is the root element of a SOAP message• It defines the XML document as a SOAP message
Advanced Web-based Systems | Misbhauddin
<?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:Envelope>
Namespace• Defines the Envelope as a
SOAP Envelope• Same as <!DOCTYPE html>
Encoding Style• Defines the data types
used in the document• Included as a URI
SOAP Envelope Element• It is a required element• It is the root element of a SOAP message• It defines the XML document as a SOAP message
Advanced Web-based Systems | Misbhauddin
<?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:Envelope>
Namespace• Defines the Envelope as a
SOAP Envelope• Same as <!DOCTYPE html>
Encoding Style• Defines the data types
used in the document• Included as a URI
SOAP Body Element• Contains the actual SOAP message
Advanced Web-based Systems | Misbhauddin
<soap:Body> <m:GetPrice xmlns:m="http://www.panda.com/prices"> <m:Item>Apples</m:Item> </m:GetPrice></soap:Body>
<soap:Body> <m:GetPriceResponse xmlns:m="http://www.panda.com/prices"> <m:Price>1.90</m:Price> </m:GetPriceResponse></soap:Body>
Request
Response
Advanced Web-based Systems | Misbhauddin
<message name="getPriceRequest"> <part name="Item" type="xs:string"/></message><message name="getPriceResponse"> <part name="Price" type="xs:double"/></message><portType name="glossaryPrice"> <operation name="getPrice"> <input message="getPriceRequest"/> <output message="getPriceResponse"/> </operation></portType> <binding type="glossaryTerms" name="b1"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> <operation> <soap:operation soapAction="http://example.com/getPrice"/> <input><soap:body use="literal"/></input> <output><soap:body use="literal"/></output> </operation></binding>
Advanced Web-based Systems | Misbhauddin
SOAP
Advantages• Platform and language
independent• Simplified communication
through proxies and firewalls• Work with different transport
protocols – HTTP, SMTP ….
Disadvantages• Slower than other protocols• Uses verbose XML• Not used for event notifications• Firewall latency• Different level of support based
on the programming language (PHP, JAVA, Python, .Net)
REST
Advanced Web-based Systems | Misbhauddin
• Representation State Transfer• Set of architectural principles – data transmitted over
HTTP• Focus on design rules for stateless service• Each resource is represented using a unique URI• Representation of the resource is returned• With each representation, client can transfer state
REST
Advanced Web-based Systems | Misbhauddin
• RESTful web services are completely stateless• Good caching infrastructure over the HTTP GET method• Well used for restricted profile devices such as mobile and PDA
(SOAP has more headers and not very useful)• Simpler than SOAP
URLS
Advanced Web-based Systems | Misbhauddin
• Identify the things that you want to operate on – meaning RESOURCES
• A web page is a type of resource
/professors List of all professors at CCSIT
/professors/Misbhauddin Identify professor named ‘Misbhauddin’
GET /professors/Misbhauddin HTTP/1.1 Host: kfu.edu.sa/ccsit
Resources are best thought of as nouns
Actions
Advanced Web-based Systems | Misbhauddin
• Lets say we want to add a new professor
Use a specific URL OR ……
Two ways
/professors/addUse HTTP Verbs
GET /professors/Misbhauddin HTTP/1.1 Host: kfu.edu.sa/ccsit
Not RESTful
HTTP Verbs
Advanced Web-based Systems | Misbhauddin
• HTTP verbs tell the server what to do with the data identified by the URL.
GET instructs the server to transmit the data identified by the URL to the client
PUT used when you wish to create or update the resource identified by the URL
DELETE used when you want to delete the resource identified by the URL of the request
POST used when the processing happen on the server
Representations
Advanced Web-based Systems | Misbhauddin
• The HTTP client and HTTP server exchange information about resources identified by URLs
• Typically resource is represented using JSON or XML• Example• Resource: person (Mohammed)• Service: contact information (GET)• Representation:• Name, address, phone number• JSON or XML format
REST Constraints
Advanced Web-based Systems | Misbhauddin
• The six constraints are:• Uniform Interface• Stateless• Cacheable• Client-Server• Layered System• Code on Demand (optional)
Uniform Interface | REST
Advanced Web-based Systems | Misbhauddin
• Defines the interface between the client and the server• Simplifies and decouples the architecture• Identification of resources; • Manipulation of resources through representations;• Self-descriptive messages;
• Fundamental to RESTful Design• HTTP Verbs: (GET, PUT, POST, DELETE)• URI (Resource Name)• HTTP Response (status, body)
Stateless| REST
Advanced Web-based Systems | Misbhauddin
• Server contains no client state• Each request contains enough context to process the
message• Self-descriptive messages;
• Any session state is kept on the client
Client-Server| REST
Advanced Web-based Systems | Misbhauddin
• Assume a disconnected system• Separation of Concern• Uniform Interface is the link between the two
Cacheable| REST
Advanced Web-based Systems | Misbhauddin
• Server responses (representations) are cacheable• Implicitly• Explicitly• Negotiated
Layered System| REST
Advanced Web-based Systems | Misbhauddin
• Client cannot assume direct connection to the server• Software or hardware intermediaries between the server
and the client• Improves scalability
Code on Demand| REST
Advanced Web-based Systems | Misbhauddin
• Server can temporarily extend the client• Transfer logic to client• Client executes logic• For example• JavaScript• Applets
• Optional
Advanced Web-based Systems | Misbhauddin
SOAP vs. REST
SOAP• Language, platform, and transport
independent (REST requires use of HTTP)• Works well in distributed enterprise
environments (REST assumes direct point-to-point communication)
• Standardized• Provides significant pre-build extensibility
in the form of the WS* standards• Built-in error handling• Automation when used with certain
language products
REST• No expensive tools require to interact
with the Web service• Smaller learning curve• Efficient (SOAP uses XML for all
messages, REST can use smaller message formats)• Fast (no extensive processing
required)• Closer to other Web technologies in
design philosophy
Advanced Web-based Systems | Misbhauddin
Recommended Reading
For the REST architecture
http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm