COP 4991 Component Based Software Development

Download Report

Transcript COP 4991 Component Based Software Development

COP 4991
Component Based Software
Development
Lecture #3
Web Services
Onyeka Ezenwoye
Agenda
Homework
Web Services
XML
SOAP
WSDL
UDDI
Conclusion
Homework 1
http://math.com/addInt?.....
RMI
registry
Client
DNS Server
http://mathObj/addInt?.....
8
http://mathObj/addInt?.....
HTTP Server
String GET(String)
Agenda
Homework
Web Services
XML
SOAP
WSDL
UDDI
Conclusion
Enterprise A
App 1
Enterprise B
App 2
App 1
COM/RMI
bridge
Java RMI
Enterprise C
App 2
App 1
App 2
COM/CORBA
bridge
COM
CORBA
Enterprise A
App 1
Enterprise B
App 2
App 1
COM/RMI
bridge
Java RMI
Enterprise C
App 2
App 1
App 2
COM/CORBA
bridge
COM
CORBA
Service Registry
Serviced
description
Subscribe
Publish
Service Consumer
Service Provider
Bind
Client
Service
Reply
Legend
program boundary
module boundary
request flow
Service Description
reply flow
What are Web Services?
Applications that can be published,
located and invoked programmatically
over the Web.
Self-contained functions that can be used
individually to provide services.
A web service is a remote procedure call
over the Internet using XML messages.
Advantages of Web Services
Cross-platform, cross-language support
– Java, .NET, PHP, Perl, Python
Based on industry standards (W3C)
– Catches the XML wave
– XML, SOAP, WSDL
Supported by many vendors
– Unlike CORBA, COM, etc
Service publication and lookup
– Conduct business without prior relationship
Loosely coupled
Web Services Technologies
The Protocol Stack
Service Discovery
Service Discovery
– UDDI
Service Description
– WSDL (XML-based)
Messaging
– SOAP (XML-based)
Service Transport
– HTTP, SMTP etc.
Service Description
XML Messaging
Service Transport
Web Services
Programming Model

RPC-based:




Synchronous model.
Similar to RMI and DCOM.
Request/response interaction
Message-based:



Document-driven.
Asynchronous model.
Publish/subscribe interaction
Agenda
Homework
Web Services
XML
SOAP
WSDL
UDDI
Conclusion
Markup History
SGML (Standard Generalized Markup L):
complex, few reliable tools
HTML (HyperText ML): simple,
unprincipled, mixes structure and display
XML (eXtensible ML): simple, yet
extensible subset of SGML to capture new
vocabularies
– Machine processible
– Comprehensible to people: easier debugging
XML Basics and Namespaces
<?xml version="1.0"?>
<arbitrary:toptag xmlns=“http://one.default.namespace/if-needed”
xmlns:arbitrary=“http://wherever.it.might.be/arbit-ns”
xmlns:random=“http://another.one/random-ns”>
<arbitrary:atag attr1=“v1” attr2=“v2”>
Optional text also known as PCDATA
<arbitrary:btag attr1=“v1” attr2=“v2” />
</arbitrary:atag>
<random:simple_tag/>
<random:atag attr3=“v3”/> <!– compare with arbitrary:atag above 
</arbitrary:toptag>
Namespaces
Many documents can have identical
elements that denote different things
– Namespaces are the XML way to classify
elements
In general, a namespace is just a tag
– An arbitrary string
– Defined to be a URI
A common practice to store a schema
– Some XML validators use these
Example namespace
<x xmlns:edi='http://ecommerce.example.org/schema'>
<!-- the "edi" prefix is bound to
http://ecommerce.example.org/schema for the "x"
element and contents -->
</x>
<x xmlns:edi='http://ecommerce.example.org/schema'>
<!-- the 'taxClass' attribute's namespace is
http://ecommerce.example.org/schema -->
<lineItem edi:taxClass="exempt">Baby food</lineItem>
</x>
Parsing and Validating
An XML document maps to a parse tree.
– Each tag ends once: nesting structure (one root)
– Each attribute occurs at most once; quoted string
Well-formed XML documents can be parsed
Applications have an explicit or implicit syntax
for their particular XML-based tags
– If explicit, may be expressed in DTDs and XML
Schemas
• Best referred to definitions elsewhere
• XML Schemas, expressed in XML, are superior to DTDs
– When docs are produced by external components, they
should be validated
XML Schemas
“Schemas” is a general term--DTDs are a
form of XML schemas
– According to the dictionary, a schema is “a
structured framework or plan”
When we say “XML Schemas,” we usually
mean the W3C XML Schema Language
– This is also known as “XML Schema
Definition” language, or XSD
DTDs and XML Schemas are all XML
schema languages
Why XML Schemas?
DTDs are written in a strange (non-XML) format
– You need separate parsers for DTDs and XML
The XML Schema Definition language solves
these problems
– XSD gives you much more control over structure and
content
– XSD is written in XML
Referring to a schema
To refer to an XML Schema in an XML document, the
reference goes in the root element:
– <?xml version="1.0"?>
<rootElement
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
(The XML Schema Instance reference is required)
xsi:noNamespaceSchemaLocation="url.xsd">
(This is where your XML Schema definition can be found)
...
</rootElement>
Simple and complex elements
A “simple” element is one that contains text
and nothing else
– A simple element cannot contain other elements
– May not be empty
– The text can be of many different types, and
may have various restrictions applied to it
If an element isn’t simple, it’s “complex”
– A complex element may have attributes
– A complex element may be empty, or it may
contain text, other elements, or both text and
other elements
Defining a simple element
A simple element is defined as
<xs:element name="name"
type="type" />
where:
– name is the name of the element
– the most common values for type are
xs:boolean
xs:integer
xs:date
xs:string
xs:decimal
xs:time
Defining an attribute
Attributes themselves are always declared as
simple types
An attribute is defined as
<xs:attribute name="name" type="type" />
where:
– name and type are the same as for xs:element
Complex elements
A complex element is defined as
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstName" type="xs:string" />
<xs:element name="lastName" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:sequence> says that elements must occur in this
order
xs:sequence
We’ve already seen an example of a
complex type whose elements must occur in
a specific order:
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstName" type="xs:string" />
<xs:element name="lastName" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
xs:all
xs:all allows elements to appear in any order
<xs:element name="person">
<xs:complexType>
<xs:all>
<xs:element name="firstName" type="xs:string" />
<xs:element name="lastName" type="xs:string" />
</xs:all>
</xs:complexType>
</xs:element>
The members of an xs:all group can occur once or
not at all
Use minOccurs="n" and maxOccurs="n" to specify how
many times an element may occur
– In this context, n may only be 0 or 1
Referencing
Once you have defined an element or
attribute (with name="..."), you can refer to
it with ref="..."
<xs:element name="person">
<xs:complexType>
<xs:all>
<xs:element name="firstName" type="xs:string" />
<xs:element name="lastName" type="xs:string" />
</xs:all>
</xs:complexType>
</xs:element>
– <xs:element name="student" ref="person">
SOAP
XML-based protocol for exchanging
structured and typed information
A SOAP message is formally specified as
XML
A stateless, one-way message exchange
paradigm
RPC, Message Exchange
Transport is mostly HTTP (POST)
Agenda
Homework
Web Services
XML
SOAP
WSDL
UDDI
Conclusion
SOAP (2)
Defines a standard format for the message exchange
Envelope
– Root element of the SOAP XML
Header
–
–
–
–
–
Optional element
Message routing information
Security
Context and transaction management information
Processing instructions for intermediaries and receiver
Body
– Mandatory element
– Contains the message payload
Structure of SOAP Messages
Soap Message
Envelope (required)
Header (optional)
Body (required)
Fault (optional)
SOAP HTTP Request Example
POST /SampleWebServiceWeb/servlet/rpcrouter HTTP/1.0
Host: localhost:9080
…
<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soapenvelope"
soap:encodingStyle="http://www.w3.org/2001/12/soapencoding">
<soap:Body xmlns:m="http://www.stock.org/stock" />
<m:GetStockPrice>
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
SOAP HTTP Response Example
HTTP/1.1 200 OK
Server: WebSphere Application Server/5.0
…
<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.stock.org/stock" />
<m:GetStockPriceResponse>
<m:Price>34.5</m:Price>
</m:GetStockPriceResponse>
</soap:Body>
</soap:Envelope>
Agenda
Homework
Web Services
XML
SOAP
WSDL
UDDI
Conclusion
What is WSDL?
Web Service
Description Language
XML Based Language for describing web
services and how to access them
WSDL is similar to the Java Language
Interfaces
What is WSDL? (2)
WSDL describes four pieces of critical data:
Interface information describing all publicly
available operations
Data type declarations for all message requests
and responses
Binding information about the transport protocol
Address information for locating the service
The WSDL Spec
definitions
types
message
portType
binding
service
documentation
import
The Main Structure of WSDL
<definition namespace = “http/… “>
<type> schema types </type>
<message> … </message>
<port> a set of operations </port>
<binding> communication protocols </binding>
<service> a list of binding and ports </service>
<definition>
Learning by Example
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="WeatherService“
targetNamespace="http://www.ecerami.com/wsdl/WeatherService.wsdl“
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.ecerami.com/wsdl/WeatherService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<message name="getWeatherRequest">
<part name="zipcode" type="xsd:string"/>
</message>
<message name="getWeatherResponse">
<part name="temperature" type="xsd:int"/>
</message>
<portType name="Weather_PortType">
<operation name="getWeather">
<input message="tns:getWeatherRequest"/>
<output message="tns:getWeatherResponse"/>
</operation>
</portType>
http://www.oreillynet.com/pub/a/webservices/2002/02/12/webservicefaqs.html?page=2
Learning by Example (2)
<binding name="Weather_Binding" type="tns:Weather_PortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getWeather">
<soap:operation soapAction=""/>
<input>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:weatherservice"
use="encoded"/>
</input>
<output>
<soap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:weatherservice"
use="encoded"/>
</output>
</operation>
</binding>
http://www.oreillynet.com/pub/a/webservices/2002/02/12/webservicefaqs.html?page=2
Learning by Example (3)
<service name="Weather_Service">
<documentation> WSDL File for Weather Service</documentation>
<port binding="tns:Weather_Binding" name="Weather_Port">
<soap:address
location="http://localhost:8080/soap/servlet/rpcrouter"/>
</port>
</service>
</definitions>
http://www.oreillynet.com/pub/a/webservices/2002/02/12/webservicefaqs.html?page=2
How do I use WSDL?
Create a SOAP client to invoke the service
– Clients
Automatically invoke the service with a WSDL
invocation tool
– Clients:
• Web Service Invocation Framework (WSIF)
RPC
Client
Call
Client Stub
Pack and send
parameters
Receive and
unpack results
Message
Message
Server Stub
Server
Receive and
unpack
parameters
Execute
procedure
Pack and
send
results
Return
Java Web Services
Web Server
Java
Client
Client stub
Or
WSIF
SOAP
AXIS SOAP
Engine
Java
application
Agenda
Homework
Web Services
XML
SOAP
WSDL
UDDI
Conclusion
What is UDDI?
Universal Description, Discovery
and Integration.
What is UDDI? (2)
The UDDI Project is an industry initiative that is working
to enable businesses to quickly, easily, and dynamically
find and transact with one another. UDDI enables a
business to:
– Describe its business and its services
– Discover other businesses that offer desired services
– Integrate with these other businesses.
What is UDDI? (3)
At its core, UDDI consists of two
parts.
– Technical specification
– The UDDI Business Registry
Basically, just a phone book
Core Data Types
businessEntity
– Business Details (name, contacts, etc.)
– White pages
businessService
– Web services provided by business (online-ordering, etc.)
– Yellow pages
bindingTemplate
– Technical details to invoke Web services
– Green pages
tModel
– Technical fingerprints used to access service specifications
How Do I use UDDI?
Use a registrar’s interface.
Use UDDI API’s using SOAP messages
Use other API’s. E.g. UDDI4J, jUDDI, etc.
Registry APIs (SOAP Messages)
Publishers API
Inquiry API
–
–
–
–
–
–
–
–
–
–
find_business
find_service
find_binding
find_tModel
find_relatedBusinesses
get_businessDetail
get_serviceDetail
get_bindingDetail
get_tModelDetail
get_businessDetailExt
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
–
save_business
save_service
save_binding
save_tModel
add_publisherAssertions
delete_business
delete_service
delete_binding
delete_publisherAssertions
delete_tModel
get_authToken
discard_authToken
get_registeredInfo
get_assertionStatusReport
get_publisherAssertions
set_publisherAssertions
Access UDDI via API’s
SOAP and XML Schema are the basis
UDDI Registry
Node
User
UDDI
SOAP Request
HTTP
Server
UDDI
SOAP Response
Create, View,
Update, and Delete
registrations
SOAP
Processor
UDDI
Registry Service
B2B Directory
Implementationneutral
© Copyright 2000 By Ariba, Inc., International Business Machines
Corporation and Microsoft Corporation. All Rights Reserved.
UDDI
WSDL
SOAP
Publish
Service Consumer
Service Provider
SOAP
Client
Service
Legend
program boundary
module boundary
request flow
Service Description
reply flow
Agenda
Homework
Web Services
XML
SOAP
WSDL
UDDI
Conclusion
Web service concerns
New Standard
Quality of service
Royalty fees?
Slow (XML parsing)
Summary
Web Services
– A web service is a piece of software that is
made available on the Internet and utilizes a
standardized XML messaging system.
– A web service can contain:
• A public interface (WSDL)
• A publishing and discovery process (UDDI)
Summary (2)
UDDI
– Universal Description, Discovery, and Integration
– Process for business to find web services of potential
business partners without random discovery.
– UDDI is:
• A business registry containing relevant information such as:
– General business information (name, description, etc.)
– Business’ Web services (description, invocation methods, etc.)
• Methods to query and publish to the registry via SOAP messages.
Summary (3)
WSDL
– Web Service Description Language
– XML Base Language for describing web services and
how to access them
– WSDL describes:
•
•
•
•
Interface information describing all publicly available functions
Data type declarations for all message requests and responses
Binding information about the transport protocol
Address information for locating the service
References
UDDI:
http://www.uddi.org/
http://www.oreillynet.com/pub/a/webservices/2002/02/12/webservicef
aqs.html?page=3
http://www.learnxmlws.com/tutors/uddi/uddi.aspx
http://www.xml.com/lpt/a/2001/04/04/webservices/index.html
http://www.javaworld.com/javaworld/jw-08-2001/jw-0824-uddi.html
http://developer.java.sun.com/developer/technicalArticles/WebServices
/WSPack
http://www.uddi4j.org
http://www.xmlmodeling.com/examples/uddi/ModelingUDDI.pdf
References
WSDL:
O’Reilly & Associates – Web Services Essentials by Ethan Cerami
http://www.oreillynet.com/pub/a/webservices/2002/02/12/webservicef
aqs.html
http://msdn.microsoft.com/library/?url=/library/enus/dnwebsrv/html/wsdlexplained.asp?frame=true
http://dcb.sun.com/practices/webservices/overviews/overview_wsdl.js
p
Acknowledgement
Rob Pearson And Ed Loo
Madhu Siddalingaiah