Top Banner
COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye
61

COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

COP 4991Component Based Software

Development

Lecture #3Web Services

Onyeka Ezenwoye

Page 2: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Agenda

Homework

Web Services

XML

SOAP

WSDL

UDDI

Conclusion

Page 3: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Homework 1

Client DNS Server

HTTP Server

String GET(String)

RMI registry

http://math.com/addInt?.....

http://mathObj/addInt?.....

http://mathObj/addInt?..... 8

Page 4: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Agenda

Homework

Web Services

XML

SOAP

WSDL

UDDI

Conclusion

Page 5: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Enterprise A

Java RMI

App 1 App 2

Enterprise B

COM

App 1 App 2

Enterprise C

CORBA

App 1 App 2

COM/RMI bridge

COM/CORBA bridge

Page 6: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Enterprise A

Java RMI

App 1 App 2

Enterprise B

COM

App 1 App 2

Enterprise C

CORBA

App 1 App 2

COM/RMI bridge

COM/CORBA bridge

proto

col c

hange

Page 7: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Subscribe Publish

Bind

Service Consumer

Client

Service Provider

Service

Service Registry

Serviced description

Legendrequest flow

reply flow

program boundary

module boundary

Reply

Service Description

Page 8: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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.

Page 9: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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

Page 10: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Web Services Technologies

The Protocol StackService Discovery– UDDI

Service Description– WSDL (XML-based)

Messaging– SOAP (XML-based)

Service Transport– HTTP, SMTP etc.

XML Messaging

Service Transport

Service Discovery

Service Description

Page 11: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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

Page 12: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Agenda

Homework

Web Services

XML

SOAP

WSDL

UDDI

Conclusion

Page 13: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Markup History

SGML (Standard Generalized Markup L): complex, few reliable toolsHTML (HyperText ML): simple, unprincipled, mixes structure and displayXML (eXtensible ML): simple, yet extensible subset of SGML to capture new vocabularies– Machine processible– Comprehensible to people: easier debugging

Page 14: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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>

Page 15: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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

Page 16: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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>

Page 17: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Parsing and ValidatingAn 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 parsedApplications 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

Page 18: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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

Page 19: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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

Page 20: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Referring to a schemaTo 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>

Page 21: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Simple and complex elementsA “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

Page 22: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Defining a simple elementA 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

Page 23: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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

Page 24: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Complex elementsA 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

Page 25: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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>

Page 26: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

xs:allxs: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 allUse minOccurs="n" and maxOccurs="n" to specify how many times an element may occur– In this context, n may only be 0 or 1

Page 27: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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">

Page 28: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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)

Page 29: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Agenda

Homework

Web Services

XML

SOAP

WSDL

UDDI

Conclusion

Page 30: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

SOAP (2)

Defines a standard format for the message exchangeEnvelope– 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

Page 31: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Soap Message

Structure of SOAP Messages

Envelope (required)

Header (optional)

Body (required)

Fault (optional)

Page 32: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

SOAP HTTP Request ExamplePOST /SampleWebServiceWeb/servlet/rpcrouter HTTP/1.0Host: localhost:9080…<?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:GetStockPrice><m:StockName>IBM</m:StockName>

</m:GetStockPrice></soap:Body>

</soap:Envelope>

Page 33: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

SOAP HTTP Response ExampleHTTP/1.1 200 OKServer: 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>

Page 34: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Agenda

Homework

Web Services

XML

SOAP

WSDL

UDDI

Conclusion

Page 35: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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

Page 36: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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

Page 37: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

The WSDL Spec

definitions

types

message

portType

binding

service

documentation

import

Page 38: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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>

Page 39: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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

Page 40: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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

Page 41: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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

Page 42: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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)

Page 43: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

RPC

Client

Call

Client Stub

Pack and send parameters

Receive and unpack

parameters

Pack and send

results

Execute procedure

ReturnReceive and

unpack results

Server Stub Server

Message

Message

Page 44: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Java Client

Client stub

Or

WSIF

AXIS SOAP Engine

Java application

SOAP

Web Server

Java Web Services

Page 45: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Agenda

Homework

Web Services

XML

SOAP

WSDL

UDDI

Conclusion

Page 46: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

What is UDDI?

Universal Description, Discovery and Integration.

Page 47: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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.

Page 48: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

What is UDDI? (3)

At its core, UDDI consists of two parts. – Technical specification

– The UDDI Business Registry

Basically, just a phone book

Page 49: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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

Page 50: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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.

Page 51: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Registry APIs (SOAP Messages)

Inquiry API– find_business

– find_service

– find_binding

– find_tModel

– find_relatedBusinesses

– get_businessDetail

– get_serviceDetail

– get_bindingDetail

– get_tModelDetail

– get_businessDetailExt

Publishers API– 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

Page 52: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Access UDDI via API’s

SOAP and XML Schema are the basis

User UDDI

SOAP Request

UDDISOAP Response

UDDI RegistryNode

HTTPServer

SOAPProcessor

UDDIRegistry Service

B2B DirectoryCreate, View, Update, and Deleteregistrations Implementation-

neutral

© Copyright 2000 By Ariba, Inc., International Business Machines Corporation and Microsoft Corporation. All Rights Reserved.

Page 53: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

SOAP Publish

SOAP

Service Consumer

Client

Service Provider

Service

UDDI

WSDL

Legendrequest flow

reply flow

program boundary

module boundary Service Description

Page 54: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Agenda

Homework

Web Services

XML

SOAP

WSDL

UDDI

Conclusion

Page 55: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Web service concerns

New Standard

Quality of service

Royalty fees?

Slow (XML parsing)

Page 56: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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)

Page 57: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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.

Page 58: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

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

Page 59: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

References

UDDI:http://www.uddi.org/http://www.oreillynet.com/pub/a/webservices/2002/02/12/webservicefaqs.html?page=3http://www.learnxmlws.com/tutors/uddi/uddi.aspxhttp://www.xml.com/lpt/a/2001/04/04/webservices/index.htmlhttp://www.javaworld.com/javaworld/jw-08-2001/jw-0824-uddi.htmlhttp://developer.java.sun.com/developer/technicalArticles/WebServices/WSPackhttp://www.uddi4j.orghttp://www.xmlmodeling.com/examples/uddi/ModelingUDDI.pdf

Page 60: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

References

WSDL:O’Reilly & Associates – Web Services Essentials by Ethan Ceramihttp://www.oreillynet.com/pub/a/webservices/2002/02/12/webservicefaqs.htmlhttp://msdn.microsoft.com/library/?url=/library/en-us/dnwebsrv/html/wsdlexplained.asp?frame=truehttp://dcb.sun.com/practices/webservices/overviews/overview_wsdl.jsp

Page 61: COP 4991 Component Based Software Development Lecture #3 Web Services Onyeka Ezenwoye.

Acknowledgement

Rob Pearson And Ed Loo

Madhu Siddalingaiah