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

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

  • View
    217

  • Download
    0

Embed Size (px)

Citation preview

COP 4991Component Based Software

Development

Lecture #3Web Services

Onyeka Ezenwoye

Agenda

Homework

Web Services

XML

SOAP

WSDL

UDDI

Conclusion

Homework 1

Client DNS Server

HTTP Server

String GET(String)

RMI registry

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

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

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

Agenda

Homework

Web Services

XML

SOAP

WSDL

UDDI

Conclusion

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

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

Subscribe Publish

Bind

Service Consumer

Client

Service Provider

Service

Service Registry

Serviced description

Legendrequest flow

reply flow

program boundary

module boundary

Reply

Service Description

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

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

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

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

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

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

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

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

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

Soap Message

Structure of SOAP Messages

Envelope (required)

Header (optional)

Body (required)

Fault (optional)

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>

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>

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

parameters

Pack and send

results

Execute procedure

ReturnReceive and

unpack results

Server Stub Server

Message

Message

Java Client

Client stub

Or

WSIF

AXIS SOAP Engine

Java application

SOAP

Web Server

Java Web Services

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)

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

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.

SOAP Publish

SOAP

Service Consumer

Client

Service Provider

Service

UDDI

WSDL

Legendrequest flow

reply flow

program boundary

module boundary Service Description

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

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

Acknowledgement

Rob Pearson And Ed Loo

Madhu Siddalingaiah