1 / 96

Web Service Protocols —Web service specifications

课程名:以服务为中心的软件开发设计与实现. Web Service Protocols —Web service specifications. Outline. Overview of Web Services XML and XML Schema The Communication Protocol (SOAP) Web Services Description (WSDL) Web Services Publication and Discovery (UDDI) Summary. Overview of Web Services. Web Services.

zody
Télécharger la présentation

Web Service Protocols —Web service specifications

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 课程名:以服务为中心的软件开发设计与实现 Web Service Protocols—Web service specifications

  2. Outline • Overview of Web Services • XML and XML Schema • The Communication Protocol (SOAP) • Web Services Description (WSDL) • Web Services Publication and Discovery (UDDI) • Summary

  3. Overview of Web Services

  4. Web Services • Web Services: Web services are a recent set of technology specifications that leverage existing proven open standards such as XML, URL, and HTTP to provide a new system-to-system communication standard. • Working Definition:Network-resident software Services accessible via standardized protocols • Simple Object Access Protocol (SOAP): very flexible remote procedure call • Lots of interest in trade press, academic community, standards bodies, . . . • Applications in e-commerce, telecom, science, GRID, government, education, . . .

  5. Categories of Web Services • Business-Oriented Web Services • ERP,CRM, • Application system integration • Consumer-Oriented Web Services • B2C website, across multi B2C systems • Device-Oriented Web Services • Support the services across different kinds of services. E.g weather report, email service • System-Oriented Web Services • Authentication • Monitoring • QoS

  6. SOA Model • As a distributed computing architecture, Web Services are the most important implementation for SOA. • SOA Model is Web Services Concept Architecture.

  7. Concept in SOA Model • Role • Services Provider • Services Requestor • Services Registry • Operation • Publish • Find • Bind • Key Component • Services • Services Description

  8. Core Standards in SOA Model • Some Standards • Web Services Description Language (WSDL) • Universal Description, Discovery and Integration (UDDI) • Simple Object Access Protocol (SOAP) • Web Service Flow Language (BPEL) • ……

  9. The Level Model of SOA Development Services Consumer Business Process Integration Architecture Qos Security Management Services Components Services Provider Existing Application Resources

  10. The Processes of Web Services Simplify and/or automate web Services • Discovery • What properties should be described? • How to efficiently query against them? • Composition • Specifying goals of a composition • Specifying constraints on a composition • Building a composition • Analysis of compositions • Invocation • Keeping enactments separated • Providing transactional guarantees • Monitoring • How to track enactments • Recovering from failedenactments

  11. Web Services Standard Stack Web Services composition: WSFL,BPEL4WS WS-CDL WS-CAF Web Services Security: XML-Encryption XML-Signature WS-Security WS-SecureConversation WS-SecurityPolicy WS-Trust Web Services Transaction: WS-Coordination WS-Transaction WS-AtomicTransaction WS-BusinessActivity Web Services Management: WSDM, WS-Manageability SPML, WS-Provisioning Publishing and discovery: UDDI, WSIL, WS-Discovery Services Description Layer: WSDL, WSCL, WSCI,WS-MetadataExchange, WS-Policy XML messaging layer: SOAP , WS-Addressing, WS-Notification, WS-Eventing, WS-Enumeration, WS-MessageDelivery, WS-Reliability,WS Reliable Messaging, WS-Resources WS-Transfer Transport layer: HTTP, SMTP, FTP, etc.

  12. Web Service Core Standards BPEL Behavior WSDL Interface SOAP IBM WebSphere Microsoft .Net Sun J2EE Message XML Schema Type XML Data Implementation Platforms Web Service Standards

  13. XML and XML Schema

  14. The structure of XML • Tag: label for a section of data • Element and Subelement: section of data beginning with <tagname> and ending with matching </tagname> Elements must be properly nested • Proper nesting • <account> … <balance> …. </balance> </account> • Improper nesting • <account> … <balance> …. </account> </balance> • Formally: every start tag must have a unique matching end tag, that is in the context of the same parent element.

  15. The structure of XML • Every document must have a single top-level element <bank> <customer> <name> Hayes </name> <street> Main </street> <city> Harrison </city> <account> <account-number> A-102 </account-number> <branch-name>Perryridge </branch-name> <balance> 400 </balance> </account> <account> … </account> </customer>. . </bank> Top level element

  16. The structure of XML • Attribute • Elements can haveattributes <account acct-type = “checking” > <account-number> A-102 </account-number> <branch-name> Perryridge </branch-name> <balance> 400 </balance> </account> • Attributes are specified by name=value pairs inside the starting tag of an element • An element may have several attributes, but each attribute name can only occur once • <account acct-type = “checking” monthly-fee=“5”>

  17. The structure of XML • Differences between element and attribute <customer name=Hayes street=Main city=Harrison> <account> <account-number> A-102 </account-number> <branch-name> Perryridge </branch-name> <balance> 400 </balance> </account> <account> … </account> </customer> Attribute can only occur once Attributes cannot be nested Attributes have no order

  18. The structure of XML • Well-Formed XML Documents • There is only one outermost element in the document (called the root element) • Each element contains an opening and a corresponding closing tag • Tags can not overlap, as in <author><name>LeeHong</author></name> • Attributes within an element have unique names • Element and tag names must be permissible

  19. The structure of XML • The Tree Model of XML Documents • There is exactly one root • There are no cycles • Each node, other than the root, has exactly one parent • Each node has a label. Element or attribute • The order of elements is important

  20. XML Example <?xml version="1.0" encoding="UTF-16"?> <!DOCTYPE email SYSTEM "email.dtd"> <email> <head> <from name="Michael Maher” address="michaelmaher@cs.gu.edu.au"/> <to name="Grigoris Antoniou“ address="grigoris@cs.unibremen.de"/> <subject>Where is your draft?</subject> </head> <body> Grigoris, where is the draft of the paper you promised me last week? </body> </email>

  21. Namespace • XML data has to be exchanged between organizations • Same tag name may have different meanings in different organizations, causing confusion on exchanged documents • Specifying a unique string as an element name avoids confusion • Better solution: use unique-name:element-name • Avoid using long unique names all over document by using XML Namespaces

  22. Namespace <Schema name="mySchema" xmlns="urn:schemas-microsoft-com:xml-data"xmlns:dt="urn:schemas-microsoft-com:datatypes" xmlns:myNS=http://www.xml_step_by_step.edu\ns.xml > Three namespaces: schema namespace datatype namespace myNS namespace

  23. Sample Code—Read XML import java.net.URL; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.io.SAXReader; public class Foo { public Document parse(URL url) throws DocumentException { SAXReader reader = new SAXReader(); Document document = reader.read(url); return document; } } • public void bar(Document document) throws DocumentException { • Element root = document.getRootElement(); • // iterate through child elements of root • for ( Iteratori = root.elementIterator(); i.hasNext(); ) { • Element element = (Element) i.next(); • // do something • } • // iterate through child elements with element name "foo" • for ( Iteratori = root.elementIterator( "foo" ); i.hasNext(); ) { • Element foo = (Element) i.next(); • // do something • } • // iterate through attributes of root • for ( Iteratori = root.attributeIterator(); i.hasNext(); ) { • Attribute attribute = (Attribute) i.next(); • // do something • } • }

  24. Sample Code—Write XML import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; public class Foo { public void createDocument() { Document document = DocumentHelper.createDocument(); Element root = document.addElement( "root" ); Element author1 = root.addElement( "author" ) .addAttribute( "name", "James" ) .addAttribute( "location", "UK" ) .addText( "James Strachan" ); Element author2 = root.addElement( "author" ) .addAttribute( "name", "Bob" ) .addAttribute( "location", "US" ) .addText( "Bob McWhirter" ); FileWriter out = new FileWriter( "foo.xml" ); document.write( out ); } }

  25. XML Schema • Database schemas constrain what information can be stored, and the data types of stored values • schemas are very important for XML data exchange • Otherwise, a site cannot automatically interpret data received from another site • Two mechanisms for specifying XML schema • Document Type Definition (DTD) • XML Schema Like DDL for database?

  26. DDL Example /*Column Information For - psn.publisher*/ Field Type Collation Null Key Default Extra Privileges Comment ------ ---------------- --------------- ------ ------ ------- ------ ------------------------------- ------- id int(11) unsigned (NULL) NO PRI 0 select,insert,update,references name varchar(255) utf8_general_ci NO select,insert,update,references /*DDL Information For - psn.publisher*/ Table Create Table --------- -------------------------------------------------------------------------------- publisher CREATE TABLE `publisher` ( `id` int(11) unsigned NOT NULL default '0', `name` varchar(255) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Publisher information from DBLP'

  27. XML Schema • XML Schema Supports • Typing of values • E.g. integer, string, etc • Also, constraints on min/max values • User defined types • Is itself specified in XML syntax, unlike DTDs • More standard representation, but verbose • Is integrated with namespaces (reuse and refine) • Many more features • List types, uniqueness and foreign key constraints, inheritance ..

  28. <xsd:schema xmlns:xsd=http://www.w3.org/2001/XMLSchema> <xsd:element name=“bank” type=“BankType”/> <xsd:element name=“account”><xsd:complexType> <xsd:sequence> <xsd:element name=“account-number” type=“xsd:string”/> <xsd:element name=“branch-name” type=“xsd:string”/> <xsd:element name=“balance” type=“xsd:decimal”/> </xsd:squence></xsd:complexType> </xsd:element> ….. definitions of customer and depositor …. <xsd:complexType name=“BankType”><xsd:squence> <xsd:element ref=“account” minOccurs=“0” maxOccurs=“unbounded”/> <xsd:element ref=“customer” minOccurs=“0” maxOccurs=“unbounded”/> <xsd:element ref=“depositor” minOccurs=“0” maxOccurs=“unbounded”/> </xsd:sequence> </xsd:complexType> </xsd:schema>

  29. XML Schema • Element Types <element name=". . ."/> with possible attributes: • ‘ type’ attribute define the element type of this element: type=". . ." (more on types later) • cardinality constraints: • minOccurs="x", where x may be any natural number (including zero) • maxOccurs="x", where x may be any natural number (including zero) or unbounded

  30. XML Schema <element name="email"/> <element name="head" minOccurs="1" maxOccurs="1"/> <element name="to" minOccurs="1"/>

  31. XML Schema • Attribute Types <attribute name=". . ."/> with possible attributes • type=". . ." • use="x", corresponds to #OPTIONAL and #IMPLIED in DTDs • use="x" value=". . .", where x may bedefault or fixed

  32. XML Schema <attribute name="id" type="ID" use="required"/> <attribute name="speaks" type="LanguageType" use="default“ value="en"/>

  33. XML Schema • Data Types • Numerical data types, including integer, Short, Byte, Long, Float,Decimal • String data types, including string, ID, IDREF, CDATA, Language • Date and time data types • user-defined data types • simple data types and complex data types

  34. XML Schema • Complex data type and extension data type • defined from already existing data types by defining some attributes (if any) and using sequence, all and choice. <complexType name="lecturerType"> <sequence> <element name="firstname" type="string" minOccurs="0" maxOccurs="unbounded"/> <element name="lastname" type="string"/> </sequence> <attribute name="title" type="string" use="optional"/> </complexType>

  35. XML Schema • <element name=“lecture” type=“lectureType”> <lecture title=“associate professor”> <firstname>gang</firstname> <lastname>Huang</lastname> </lecture>

  36. XML Schema Data Type Extension: existing data types can be extended by new elements or attributes <complexType name="extendedLecturerType"> <extension base="lecturerType"> <sequence> <element name="email" type="string" minOccurs="0" maxOccurs="1"/> </sequence> <attribute name="rank" type="string" use="required"/> </extension> </complexType>

  37. XML Schema • Restriction data type and simple data type be defined by restricting existing data types <complexType name="restrictedLecturerType"> <restriction base="lecturerType"> <sequence> <element name="firstname" type="string" minOccurs="1" maxOccurs="2"/> </sequence> <attribute name="title" type="string" use="required"/> </restriction> </complexType>

  38. XML schema • Simple data types can also be defined by restricting existing data types. <simpleType name="dayOfMonth"> <restriction base="integer"> <minInclusive value="1"/> <maxInclusive value="31"/> </restriction> </simpleType>

  39. The Communication Protocol(SOAP)

  40. Why Simple Object Access Protocol • SOAP is an XML messaging protocol that is independent of any specific transport protocol. • Light weight replacement for complicated distributed object technology • Originally for BizTalk (Microsoft/UserLand/DevelopMentor) • Now a W3C standard • Based on XML

  41. Envelope contains Header Body Header is optional Out-of-band information such as… Authentication information Message routes Logging Transaction flow Body contains XML body of RPC call SOAP Envelope SOAP Header Header Block . . . Header Block SOAP Body Body Block . . . Body Block SOAP Message Structure

  42. SOAP Example

  43. SOAP Example

  44. Web Services Description Language(WSDL)

  45. Web Services Description Language (WSDL) • WSDL is an XML-based interface definition language that separates function from implementation, and enables design by contract as recommended by SOA. • WSDL defines • What does Services do –interface • Access specification –how • Location of the Services –where

  46. WSDL Specification types message message message porttype operation operation operation binding service port

  47. Ingredients of WSDL Supports Interface Port Type Operation How to invoke Input & Output Formats & Protocols Accessspecification Binding Message How to encode Implements Provides Port Services Endpoints

  48. Main Structure of WSDL <definitions namespace = “http://… ”> <types> XML schema types </type> <message> definition of a message </message> <portType> a set of operations </portType> <binding> communication protocols </binding> <Services> a list of binding and ports </Services> </definitions>

  49. Types • <types> define data types used in defining messages • XML Schema, DTD, and etc. • XML Schema must be supported by any vendor of WSDL conformant products <types> <schema targetNamespace=“http://example.com/stockquote.xsd”xmlns=“http://www.w3.org/2000/10/XMLSchema”> <element name=“TradePriceRequest”> <complexType> <all> <element name=“tickerSymbol” type=“string“ minOccur = “1” maxOccur=“10”/> <element name = “payment”> <complexType> <choice> <element name = “account” type=“string” /> <element name = “creditcard” type=“string” /> </choice> </complexType> </element> </all> </complexType> </element> </schema> </types>

More Related