600 likes | 747 Views
INF5120 Modellbasert systemutvikling. Web Services XML Schema WSDL BPEL Forelesning 26.03.2007 Roy Grønmo roy.gronmo@sintef.no. Outline. Web Services – Infrastructure and Architecture XML Introduction XML Schema Web Service Description Language (WSDL)
E N D
INF5120Modellbasert systemutvikling Web Services XML Schema WSDL BPEL Forelesning 26.03.2007 Roy Grønmo roy.gronmo@sintef.no
Outline • Web Services – Infrastructure and Architecture • XML Introduction • XML Schema • Web Service Description Language (WSDL) • Business Process Execution Language (BPEL)
What is a Web service? • The term “Web services” is confusing. • There are many things that are referred to as “Web services”. • Adding to the confusion is the term “services” which is interpreted differently by different people.
Work performed or offered by a software system (possibly including human resources as well.) Web is short for World Wide Web. Software services performed or offered on the Web, using open Internet standards and technologies. What is a Web service? Web service
Definition (W3C): Web service • “A Web service is a software system designed to support interoperable machine-to-machine interaction over a network. It has an interface described in a machine-processable format (specifically WSDL). Other systems interact with the Web service in a manner prescribed by its description using SOAP-messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web-related standards.” - W3C Web Services Glossary, http://www.w3.org/TR/ws-gloss/
Characteristics of a basic Web service • Fundamental requirements: • It receives service requests and sends service replies over HTTP • Service requests – input data/parameters • Service responses – output data/parameters • Data is normally formatted as an XML document • SOAP (Simple Object Access Protocol) • Interface w/ operations and associated bindings and protocols are described using WSDL • Additionally, a Web service may: • Be registered with a discovery agent through which it can be located, typically UDDI.
This part of the tutorial focuses on understanding the Web service technologies for messaging, description and composition such as XSD, WSDL and WS-BPEL. Web services stack Conceptualstack Technologystack
WS-CHOR ____________________________________________________________ Interaction Sequencing (Co)Constraints EGO-Centric Workflow Process Description Business EntitiesWeb Service Interfaces BPEL ____________________________________________________________ (Syntactic) Web Service Interface Description Messaging Encoding WSDL ____________________________________________________________ Raw XML ebXML SOAP EDI “Binary” Bindings and Endpoint Descriptions Underlying Protocols XSD SMTP/EMAIL MQ-Series HTTP/WEB ____________________________________________________________ XML Message Schema Definition VANs FTP Web services – a conceptual view
Relationship between Architecture model and Web Services UML Activity BPEL UML Interface WSDL UML Class XML Schema
Model-driven Web Services –Two alternatives ATL 1 PIM (COMET models) PSM (WS UML Profile) Model-to-model MOFScript MOFScript 1 Model-to-text Model-to-text • Transformation choices: • fixed • config file • user is prompted 2 Web Service (XML, Textual) 1. Transformation in two steps via UML profile 2. Transformation in one step transformation
XML - a Metameta Language XML SGML Metameta/How to define schema MathML XSL SMIL OFX HTML Meta/Schema XML Doc XSL Doc HTML Doc Instances/Documents
XML Schema to represent the DTD in XML syntax and express additional constraints RDF Resource Description Framework - to add metadata XSL(T) to rearrange/restructure an XML document … and to prepare a document for rendering based on an XSL document Document Type Definition (DTD) XML Document XML Query to query sets of XML documents XPointer to position a cursor in an XML document XLink to create complex links
Example XML Document <?XML version="1.0"?> <memo clearance-level = “0” status = “draft”> <memo-header> <from>Brian Smith</from> <to>Mary Brown</to> <date>March 3, 1998</date> <subject>excessive overtime</subject></memo-header> <memo-body><para>The Flame Project team has been working overtime for weeks and weeks. Let’s take the group to lunch on Friday. </para></memo-body> </memo>
Example XML Document <?XML version="1.0"?> <memo clearance-level = “0” status = “draft”> <memo-header> <from>Brian Smith</from> <to>Mary Brown</to> <date>March 3, 1998</date> <subject>excessive overtime</subject></memo-header> <memo-body><para>The Flame Project team has been working overtime for weeks and weeks. Let’s take the group to lunch on Friday. </para></memo-body> </memo> Start- and end-tags come in pairs
the content of simple elements:appears between start tag and end tag <?XML version="1.0"?> <memo clearance-level = “0” status = “draft”> <memo-header> Text content <from>Brian Smith</from> <to>Mary Brown</to> <date>March 3, 1998</date> <subject>excessive overtime</subject></memo-header> <memo-body><para>The Flame Project team has been working overtime for weeks and weeks. Let’s buy pizza for the group on Friday. </para></memo-body> </memo>
the content of compound elements:appears between start tag and end tag <?XML version="1.0"?> <memo clearance-level = “0” status = “draft”> <memo-header> <from>Brian Smith</from> <to>Mary Brown</to> <date>March 3, 1998</date> <subject>excessive overtime</subject></memo-header> <memo-body><para>The Flame Project team has been working overtime for weeks and weeks. Let’s buy pizza for the group on Friday. </para></memo-body> </memo> a compound element includes all of the complete subelements: the tags and content of the subelements
Attributes in XML In the document, we see: <memo clearance-level = “0” status = “draft”> Attributes are associated with elements….and the assignment of values to attributes always appear in the start tag for the element. tag name attribute name attribute value attribute name attribute value
Namespaces Example Slightly modified listings document <?xml version="1.0"> <Recent-Listings Area="Raleigh Hills" Date="March 97” xmlns=“http://www.century21.com/listings.dtd” xmlns:mls="urn:uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" > <For-Sale> <Home id="h1"> <Address>8225 SW Canyon Lane</Address> <mls:Structure> <Num-Beds>3</Num-Beds> <Num-Baths>2</Num-Baths>... Default Namespace “Named” Namespace Prefix
XML is extensively used – Examples • XML Metadata Interchange (XMI) • XSLT – programming language for transformation • Web Services: XML Schemas, WSDL, SOAP, BPEL • Storage/Exchange formats • Configuration files • Advantage: Tool support for parsing, validation, editing, visualization, ease of debugging etc. • Disadvantage: Poor readability, efficiency (compared to binary)
XML Schema Definition (XSD) • Define the legal building blocks of an XML document: • Defines elements that can appear in a document. • Defines attributes that can appear in a document. • Defines which elements are child elements. • Defines the order of child elements. • Defines the number of child elements. • Defines whether an element is empty or can include text. • Defines data types for elements and attributes. • Defines default and fixed values for elements and attributes.
Simple types • Simple types are defined by restricting a built-in-type or another simple type <simpleType name=“age”> <restriction base=“integer”> <minInclusive value=“0”/> <maxInclusive value=“130”/> </restriction> </simpleType> • fourteen facets to restrict including: pattern, enumeration, length(3), period and duration
Another Example <simpleType name="US-Flag-Colors"> <restriction base="string"> <enumeration value="red"/> <enumeration value="white"/> <enumeration value="blue"/> </restriction> </simpleType>
Defining complex types <xsd:complexType name="Address" > <xsd:sequence> <xsd:element name="name" type=”xsd:string" /> <xsd:element name="street" type=”xsd:string" />… <xsd:element name="zip" type=”xsd:decimal" /> </xsd:sequence> <attribute name=”country" type=”xsd:string" /> </xsd:complexType> <xsd:complexType name="PurchaseOrderType"> <xsd:sequence> <xsd:element name="shipTo" type="Address" /> ... </xsd:complexType>
Document instance of purchase order <PurchaseOrder orderDate="1999-05-20"> <shipTo country="US"> <name>Alice Smith</name> <street>123 Maple Street</street> <city>Mill Valley</city> <state>CA</state> <zip>90952</zip> </shipTo> ... </PurchaseOrder> name=“shipTo" type="Address"
<complexType> or <simpleType>? • When do you use the complexType element and when do you use the simpleType element? • Use the complexType element when you want to define child elements and/or attributes of an element • Use the simpleType element when you want to create a new type that is a refinement of a built-in type (string, integer, etc)
Defining attributes <attributename="Category" use="required"> <simpleType> <restriction base="string"> <enumeration value="autobiography"/> <enumeration value="non-fiction"/> <enumeration value="fiction"/> </restriction> </simpleType> </attribute> • Note: attributes can only have simpleTypes (i.e., attributes cannot have child elements). Anonomous type
Notes about Attributes • The attribute declarations always come last, after the element declarations. • The attributes are always with respect to the element that they are defined (nested) within. <element name="foo"> <complexType> <sequence> … </sequence> <attribute name="bar" …/> <attribute name="boo" …/> </complexType> </element> "bar and boo are attributes of foo"
Inheritance: Extending complex types <complexType name="USAddress"> <extension base="Address"> <sequence> <element name="zip" type="xsd:string"/> </sequence> </extension> </complexType>
Elements <element name="zip” type="xsd:string"/> tag name in instance document type is either built-in types, simpleTypes or complexTypes XML instance: <zip>90210</zip>
XSD: XML text editor • Can also be built using simple text editors • XML editors gives contextual support, e.g. like auto-completion, suggestions for elements, etc., as well as validation of the XML document. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> </xs:schema> • Inside here goes: • elements • complexTypes • simpleTypes
XSD: UML profile for XSD • UML representation of XML schema. • Useful in a UML-centric development method if the modelling environment supports generation/import of XSD documents.
Making a SOAP function call over HTTP HTTP Request Header Body XML Data HTTP Response Header Body XML Data
The SOAP Envelope <SOAP:Envelope> <SOAP:Header></SOAP:Header> <SOAP:Body> <m:FunctionName> <paramName1>paramValue1</paramName1> <paramName2>paramValue2</paramName2> </m:FunctionName> </SOAP:Body> </SOAP:Envelope> Optional
Web Services Description Language (WSDL) • Purpose • Web services need to be defined in a consistent manner so that they can be discovered by and interfaced with other services and applications. • The Web Services Description Language is a W3C specification providing the foremost language for the description of Web service definitions. • W3C, "Web Services Description Language (WSDL) Version 2.0 Part 1: Core Language", World Wide Web Consortium (W3C), W3C Working Draft, 3 August 2004. http://www.w3.org/TR/2004/WD-wsdl20-20040803/
Business EntitiesWeb Service Interfaces (Syntactic) Web Service Interface Description Messaging Encoding WSDL ____________________________________________________________ Raw XML ebXML SOAP EDI “Binary” Bindings and Endpoint Descriptions Underlying Protocols SMTP/EMAIL MQ-Series HTTP/WEB VANs FTP WSDL: Conceptual view
WSDL: Conceptual model WS Client WS Interface WS Provider Operations Invoked through Ports Ports Porttype Operations Concrete Endpoint Address Operation Name,Abstract Message Parts Schema Message Exchange Pattern (Reusable) Binding Concrete Message Encoding Concrete Messaging Protocol
Request-Response Solicit-Response One-Way Notification WSDL: Message exchange patterns WS Client WS Provider Time
A container for data type definitions WSDL Component WSDL Document Include 0..1 0..1 + Location Import + NameSpace Schema A collection of related endpoints Types + Location + TargetNameSpace 0..* 0..* 0..1 0..1 Definition Element Service + Name + Name + Name + TargetNameSpace + BaseType 0..* 0..* + MinOccurs An abstract, typed definition of the data being communicated A single endpoint defined as a combination of a binding and a network address + MaxOccurs 1..* 1..* Port 0..* 0..* Part + Name 0..* 0..* Message + Name 1 1 + Name + Type + Element 0..1 0..1 0..1 0..1 0..1 0..1 +fault +output 0..* 0..* 1 1 0..* 0..* +input Binding Port Type + Name + Name 1 1 1 1 A concrete protocol and data format specification for a particular port type 1..* 1..* Operation + Name An abstract, description of an action supported by the service An abstract set of operations supported by one or more endpoints WSDL 1.1 metamodel
UML profile for WSDL UML representation Text representation
<types><schema> <complexType name="CreditCard">... <element name="number" type="string"/> <element name="expires" type="date"/>... </types> <message name="validateRequest"> <part name="card" type="CreditCard"/></message>... <portType name="Payment"> <operation name="validate"> <input message="validateRequest"/> <output message="validateResponse"/> </operation></portType> <portType name="TransactionWFS"> <operation name="getCapabilities">... <operation name="describeFeatureType">... <operation name="getFeature">... <operation name="lockFeature">... <operation name="transaction">... <binding name="PaymentSOAPBinding" type="Payment"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" ...> <operation name="validate">...</binding> <binding name="TransactionWFSSOAPBinding" type="Payment"> <operation name="getCapabilities">... <operation name="describeFeatureType">... <operation name="getFeature">... <operation name="lockFeature">... <operation name="transaction">...</binding> <service name="myWebService"> <port name="Payment_Port” binding="PaymentSOAPBinding"> <soap:address location=”..www.myWebService.com"/>... <port name="TransactionWFS_Port” binding="TransactionWFSSOAPBinding">… Class Copy-down Inheritance Interface Interface Realize BusinessService
BPEL BPEL is a Web service composition language. It defines how to compose other Web services so to accomplish a more complex task. A BPEL engine is capable of executing the composite service described by BPEL. The outcome will be a composite BPEL-defined Web service which itself can be regarded as a Web service.
BPEL language • XML notation • Interaction with other Web services: • <receive>. Wait for an incoming message. Typically at the process start • <invoke>. Call another Web service • <reply>. Send a response message from the entire BPEL service • Control flow • <sequence>. Sequential control flow • <flow>. Parallel control flow • <switch>. Conditional branching • <while>. Loop • Data flow • <variable>. Defines the data objects involved • <assign>. Copy a data object from one variable to another possibly w/ data transformation
BPEL: Simplified view A BPEL process is a composite Web service with a WSDL description.