1 / 84

Ace104 Lecture 7

Ace104 Lecture 7. WSDL in depth. Advanced Schema features (required for understanding wsdl). <xs:any>. Can use <xs:any namespace=“…”> in schema to specify extensibility elements “any element can go here from the specific namespaces”

patty
Download Presentation

Ace104 Lecture 7

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. Ace104Lecture 7 WSDL in depth

  2. Advanced Schema features(required for understanding wsdl)

  3. <xs:any> • Can use <xs:any namespace=“…”> in schema to specify extensibility elements • “any element can go here from the specific namespaces” • Common technique to allow flexibility in instance documents without forcing change to schema • We will see the wsdl files rely heavily on this • Strong implications for validation

  4. <xs:any> <xs:any> id = xs:ID maxOccurs = ( xs:nonNegativeInteger | “unbounded” ) : “1” minOccurs = xs:nonNegativeInteger : “1” namespace = ( (“##any” | “##other” ) | list of (xs:anyURI | “##targetNamespace” | “##local”) ) ) : “##any” processContents = (“skip” | “lax” | “strict”) : “strict” ##any: any element from any namespace ##other: any element from any namespace other than the target ##targetNamespace: any element from the target skip: do not attempt validation of these elements (by looking for schema) lax : attempt validation but don’t complain if you can’t find schema strict: attempt validation and error if you can’t find schema

  5. Validation • How is validation done for these <xs:any> elements? • Very important: up to processing tool to try to find schema • You can use xsi:schemaLocation within specific element • You can leave it up to the tool to figure out. Most will • Look up URI and see if anything is there • Have copy of standard schema (soap-enc, etc.) • Look it up in a registry

  6. WeatherReport.xsd <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wthr="http://www.ccis.com/ace104/weather" elementFormDefault="qualified" targetNamespace="http://www.cccis.com/ace104/weather"> <xs:element name="weatherReport"> <xs:complexType> <xs:sequence> <xs:element name="temperature" type="xs:float"/> <xs:element name="windSpeed" type="xs:integer"/> <xs:element name="humidity" type="xs:float"/> <xs:any namespace="http://www.cccis.com/ace104/weather/cities" processContents="strict"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>

  7. Cities.xsd <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.cccis.com/ace104/weather/cities" elementFormDefault="qualified"> <xs:element name="city"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="state"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="FL"/> <xs:enumeration value="AL"/> <xs:enumeration value="MD"/> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="zipcode" type="xs:string”/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>

  8. Weather.xml <?xml version="1.0" encoding="UTF-8"?> <wthr:weatherReport xmlns:wthr="http://www.cccis.com/ace104/weather" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.cccis.com/ace104/weather file:/Users/siegela/Desktop/xs_any_examples.xsd"> <wthr:temperature>32</wthr:temperature> <wthr:windSpeed>23</wthr:windSpeed> <wthr:humidity>100</wthr:humidity> <c:city xmlns:c="http://www.cccis.com/ace104/weather/cities" xsi:schemaLocation="http://www.cccis.com/ace104/weather/cities file:/Users/siegela/Desktop/cities.xsd"> <c:name>Miami</c:name> <c:state>FL</c:state> <c:zipcode>33169</c:zipcode> </c:city> </wthr:weatherReport> Most explicit way to tell validator where schema is located is to Use schemaLocation

  9. Class example • Step 1 • Create schema named itinerary.xsd • Use targetNamespace=omega.travel.com • Use ElementFormDefault=qualified • Root element is Itinerary • Sequence • dateGenerated, min=1 max=1, type=date • passenger, min=1, max=unbounded, type = passengerType • departing, min=1, max=1, type=airportCode • returning, min=1, max=1, type=airportCode • preferences, min=1, max=1, type=preferenceType • passengerType: complex -> last, first each of type string • airportCode: simple -> enumeration -- ORD, MIA, etc. • preferences: complex -> meal, seating • meal: simple -> enumeration -- vegan, veg, meat-n-fat, lowcal • seating: simple -> enumeration -- aisle, window, center

  10. Class example, cont. • Step 2: • Generate sample valid sample xml • Step 3: Make .xsd more flexible • Allow unspecified elements to be placed after element <last> in <passenger> element. • Specify <xs:any namespace=“##other” processContents=“lax”/> • Revalidate xml • Add minOccurs=0 to line above to not require presence of new elements

  11. Class Example, cont. • Create new schema called fbitravel.xsd • Use namespace travel.fbi.gov • Add root element securityCode of type <xs:double> • In sample .xml, add a <securityCode> element in the <xs:any> location and explicitly add xsi:schemaLocation to that element. • Does validation work?

  12. XMLschema-instance • The XML schema standard also defines several attributes for direct use in any XML documents. • These attributes are in a different namespace • http://www.w3.org/2001/XMLSchema-instance • We have used one of these extensively already -- xsi:schemaLocation • Note that the standard prefix is xsi: but in practice, any prefix can be used. All schema processors have appropriate attribute declarations for these attributes built in

  13. xsi:schemaLocation • Recall that the xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes can be used in a document to provide hints as to the physical location of schema documents which may be used for assessment • Processing tool may choose to override these suggestions to avoid breaking instance documents if a resource moves

  14. <xsi:type> attribute • The simple or complex type definition used in validation of an element is usually determined by reference to the appropriate schema components. • An element information item in an instance may, however, explicitly assert its type using the attribute xsi:type. • The value of this attribute is a Qname • As we will see this is used in SOAP documents

  15. Why xsi:type? • Why would we want the instance document to specify the type? • Not really necessary simply for validation, since we could use xs:union to allow an element definition to hold several types simultaneously • Becomes important when we need the tool that reads the instance-document to know what type occurred in the instance doc!

  16. <methodCall> <methodName> <getStateName> </methodName> <params> <param> <value> <i4> 41 </i4> </value> </param> </params> </methodCall> <methodCall> <methodName> <getStateName> </methodName> <params> <param> <value xsi:type=“xs:int”> 41 </value> </param> </params> </methodCall> Example rpc-type mechanism showing flexibility of defining type withing xml instance

  17. What about schema • There are a few types of relationships that can exist between schema type definition and the xsi:type • Corresponding schema contains different type definition and xsi:type=“..” overrides it • Corresponding schema has general type and xsi:type=“..” restricts it • For complext types, corresponding schema has base or abstract type and xsi:type=“..” subclasses it (see next slide)

  18. Abstract types and xsi:type • As mentioned, another use of xsi:type is to specify a concrete instance of an abstract complex type within an instance document • It can also be used to specify a concrete subclass of a non-abstract type, though this is often not as useful since it does not prohibit the base type from appearing in the instance document

  19. bookBase <xs:complexType name="bookbase" abstract="true"> <xs:sequence> <xs:element ref="isbn"/> <xs:element ref="title" minOccurs="0" maxOccurs="unbounded"/> <xs:element ref="author" minOccurs="0" maxOccurs="unbounded"/> <xs:element ref="character" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute ref="id"/> <xs:attribute ref="title"/> <xs:attribute ref="available"/> </xs:complexType> This derived type accepts only title attributes (note that element is implied eliminated by not appearing in the sequence, whereas attribute is implied to still exist).

  20. bookTitleAttribute <xs:complexType name="bookTitleAttribute"> <xs:complexContent> <xs:restriction base="bookbase"> <xs:sequence> <xs:element ref="isbn"/> <xs:element ref="author" minOccurs="0" maxOccurs="unbounded"/> <xs:element ref="character" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:restriction> </xs:complexContent> </xs:complexType> The base type accepts book elements with optional titles defined as attributes or elements.

  21. bookTitleElements <xs:complexType name="bookTitleElements"> <xs:complexContent> <xs:restriction base="bookbase"> <xs:sequence> <xs:element ref="isbn"/> <xs:element ref="title" minOccurs="1" maxOccurs="unbounded"/> <xs:element ref="author" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute ref="title" use="prohibited"/> </xs:restriction> </xs:complexContent> </xs:complexType> This type does not allow titles as attributes but only as one or more elements

  22. Corresponding XML <book id=“12345” available=“true” xsi:type=“bookTitleElements”> <isbn> 9294854839 </isbn> <title lang=“en”> Apology for Raymond de Sabonde </title> <title lang=“fr”> Apologie par Raymond de Sabonde </title> … </book> this is required if type is abstract Note: if bookBase is not abstract then a bookBase type will validate also

  23. Another example but using extension rather than restriction

  24. ?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="class"> <xs:complexType> <xs:sequence> <xs:element name="title"> <xs:complexType> <xs:simpleContent> <xs:extension base="xs:string"> <xs:attribute name="courseID" type="xs:string"/> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> <xs:element name="students" type="student" minOccurs="2" maxOccurs="200"/> <xs:element name="location" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> Here student type will be declared as abstract and several subtypes will be defined within the same schema

  25. Student base type <xs:complexType name="student" abstract="true"> <xs:sequence> <xs:element name="lastName" type="xs:string"/> <xs:element name="firstName" type="xs:string"/> <xs:element name="social" type="xs:NMTOKEN"/> </xs:sequence> </xs:complexType>

  26. <xs:complexType name="gradStudent"> <xs:complexContent> <xs:extension base="student"> <xs:sequence> <xs:element name="funded" type="xs:boolean"/> <xs:element name="gpa" type="xs:float"/> <xs:element name="advisor" type="xs:string"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> Says that gradStudent is a sequence that has everything in student sequence plus three additional elements funded, gpa, and advisor

  27. <xs:complexType name="undergradStudent"> <xs:complexContent> <xs:extension base="student"> <xs:sequence> <xs:element name="gpa" type="xs:float"/> <xs:element name="major" type="xs:string"/> <xs:element name="class" type="xs:int"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complexType> Says that undergradStudent is a sequence that has everything in student sequence plus three additional elements gpa, major, and class

  28. <?xml version="1.0" encoding="UTF-8"?> <class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:/Users/siegela/Desktop/class.xsd"> <title>title0</title> <students xsi:type="gradStudent"> <lastName>lastName0</lastName> <firstName>firstName0</firstName> <social>social0</social> <funded>true</funded> <gpa>3.2</gpa> <advisor>Smith</advisor> </students> <students xsi:type="undergradStudent"> <lastName>lastName1</lastName> <firstName>firstName1</firstName> <social>social1</social> <gpa>3.5</gpa> <major>Philosophy</major> <class>2010</class> </students> <location>"room 201"</location> </class> Sample XML instance document showing how required xsi:type attribute selects subclass

  29. A little more SOAP

  30. SOAP Reminder • Recall that there are three parts to SOAP • A generic message envelope • This is generally considered a nice thing • A suggested set of encoding rules (known as “Section 5” or “SOAP encoding”) • This is more frequently discredited these days • A standard for represent remote procedure calls • This is somewhat discredited (at best it is harmless)

  31. SOAP Schema, Envelope element <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.xmlsoap.org/soap/envelope/" targetNamespace="http://schemas.xmlsoap.org/soap/envelope/" > <!-- Envelope, header and body --> <xs:element name="Envelope" type="tns:Envelope" /> <xs:complexType name="Envelope" > <xs:sequence> <xs:element ref="tns:Header" minOccurs="0" /> <xs:element ref="tns:Body" minOccurs="1" /> <xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax" /> </xs:sequence> <xs:anyAttribute namespace="##other" processContents="lax" /> </xs:complexType> </xs:schema>

  32. SOAP Schema, Header element <xs:element name="Header" type="tns:Header" /> <xs:complexType name="Header" > <xs:sequence> <xs:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="lax" /> </xs:sequence> <xs:anyAttribute namespace="##other" processContents="lax" /> </xs:complexType>

  33. SOAP Schema, Body element <xs:element name="Body" type="tns:Body" /> <xs:complexType name="Body" > <xs:sequence> <xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded” processContents="lax" /> </xs:sequence> <xs:anyAttribute namespace="##any" processContents="lax" > <xs:annotation> <xs:documentation> Prose in the spec does not specify that attributes are allowed on the Body element </xs:documentation> </xs:annotation> </xs:anyAttribute> </xs:complexType>

  34. <!-- Global Attributes. The following attributes are intended to be usable via qualified attribute names on any complex type referencing them. --> <xs:attribute name="mustUnderstand" > <xs:simpleType> <xs:restriction base='xs:boolean'> <xs:pattern value='0|1' /> </xs:restriction> </xs:simpleType> </xs:attribute> <xs:attribute name="actor" type="xs:anyURI" /> <xs:simpleType name="encodingStyle" > <xs:annotation> <xs:documentation> 'encodingStyle' indicates any canonicalization conventions followed in the contents of the containing element. For example, the value 'http://schemas.xmlsoap.org/soap/encoding/’ indicates the pattern described in SOAP specification </xs:documentation> </xs:annotation> <xs:list itemType="xs:anyURI" /> </xs:simpleType> <xs:attribute name="encodingStyle" type="tns:encodingStyle" /> <xs:attributeGroup name="encodingStyle" > <xs:attribute ref="tns:encodingStyle" /> </xs:attributeGroup>

  35. Fault element <xs:element name="Fault" type="tns:Fault" /> <xs:complexType name="Fault" final="extension" > <xs:annotation> <xs:documentation> Fault reporting structure </xs:documentation> </xs:annotation> <xs:sequence> <xs:element name="faultcode" type="xs:QName" /> <xs:element name="faultstring" type="xs:string" /> <xs:element name="faultactor" type="xs:anyURI" minOccurs="0" /> <xs:element name="detail" type="tns:detail" minOccurs="0" /> </xs:sequence> </xs:complexType>

  36. SOAP Schema, detail type <xs:complexType name="detail"> <xs:sequence> <xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" processContents="lax" /> </xs:sequence> <xs:anyAttribute namespace="##any" processContents="lax" /> </xs:complexType>

  37. SOAP Encoding • Recall that in general a SOAP message needs to be able to describe the data that it is carrying to the receiver • Two ways to do this • Refer to a schema from within the SOAP message and use regular xs types (“literal”) • Using soap encoding (or some other encoding standard) directly within the XML (“encoded”) • Soap-enc relies on xsi:type embedded in XML, as we just saw! • Additional rules for arrays, object graphs, etc.

  38. Soap-enc with simple types • Simple types are represented using standards xs types as <env: Envelope …> <env:Body> <identifier xsi:type=“xsd:string” > asdkfj3 339039393 </identifier> <date xsi:type=“xsd:date” >29 October 2002</date>

  39. Literal • The literal way to do this does not include a type in the XML but rather validates against a schema <purchaseOrder xmlns=http://www.cccis.com/po/schema xmlns:xsi=“http://www.w3.org.2001/XMLSchema-instance xsi:schemaLocation=“http://www.cccis.com/po/schema po.xsd” > <identifier>87 kdjfkl2393894udfk </identifier> </purchaseOrder>

  40. Compound Types • Soap-enc defines struct and array types that are used in SOAP documents • Struct is used for aggregate types whose components have (possibly) different names. It does not carry any special syntax (as we’ll see) • array is used when all components have the same name • The soap-enc schema is not intended to be used by itself, but rather embedded within the SOAP schema using the <any namespace=…> as we saw earlier (with lax processing).

  41. <billingAddress> <name>Andrew Klein</name> <street> 901 NW 200 st.</street> <city>Miami</city> <state>FL</state> <zip>33169</zip> </billingAddress> <env:Envelope xmlns:env=“http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsd=“http://www.w3.org/2001/XMLSchema” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance xmlns:enc=“http://schemas.xmlsoap.org/soap/encoding/ xmlns:ns0=“http://www.cccis.com/xml env:encodingStyle=“http://schemas.xmlsoap.org/soap/encoding/> <env:Body> <ns0:billingAdress> <name xsi:type=“xsd:string”>Andrew Klein</name> <street xsi:type=“xsd:string”>901 NW 200 st.</street> … <city xsi:type=“xsd:string>33169</zip> </ns0:billingAddress> Names matter but order doesn’t

  42. <emailAddresses> <email>siegela@uchicago.edu</email> <email> rbaker@cccis.com</email> </emailAddresses> <env:Envelope xmlns:env=“http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsd=“http://www.w3.org/2001/XMLSchema” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance xmlns:enc=“http://schemas.xmlsoap.org/soap/encoding/ xmlns:ns0=“http://www.cccis.com/xml env:encodingStyle=“http://schemas.xmlsoap.org/soap/encoding/> <env:Body> <ns0:emailAddresses xsi:type=“enc:Array” ecn:arrayType=“xsd:String[2]”> <email xsi:type=“xsd:string”>siegela@uchicago.edu</email> <email xsi:type=“xsd:string”>rbaker@cccis.com</email> </ns0:emailAddresses> If all types are the same these are optional

  43. 2d arrays, etc. • Soap encoding also allows multidimensional arrays using references, etc. <ns0:ArrayOfPaymentDetail id=“ID1 xsi:type=“enc:Array” enc:arrayType=“ns0:Paymentdetail[2]”> <item href=“#ID2”/> <item href=“#ID3/> </ns0:ArrayOfPaymentDetail>

  44. Web Services

  45. Web Services • Here is a simple starting definition • “A Web Service is a software component that is described via WSDL and is capable of being accessed via standard network protocols such as but not limited to SOAP over HTTP” - Oasis Consortium

  46. WSDL • WSDL (Web Services Definitons Language) is the Interface Definition Language (IDL) of web services. • To truly understand web services it is necessary to have a very deep understanding of the WSDL standard (and its associated problems) • Relying on high level tools for rpc is not adequate!

  47. WSDL • WSDL is an XML format for describing network services as a set of endpoints operating on messages containing either document-oriented or procedure-oriented information. • The operations and messages are described abstractly, and then bound to a concrete network protocol and message formats to define an endpoint. • Related concrete endpoints are combined into abstract endpoints (services). • WSDL is extensible to allow description of endpoints and their messages regardless of what message formats or network protocols are used to communicate, however, the only bindings described in the SOAP standard describe how to use WSDL in conjunction with SOAP 1.1, HTTP GET/POST, and MIME.

  48. WSDL Components • a WSDL document uses the following elements in the definition of network services: • Types • a container for data type definitions using some type system (such as XSD). • Message • an abstract, typed definition of the data being communicated. • Operation • an abstract description of an action supported by the service. • Port Type • an abstract set of operations supported by one or more endpoints. • Binding • a concrete protocol and data format specification for a particular port type. • Port • a single endpoint defined as a combination of a binding and a network address. • Service • a collection of related endpoints.

  49. ?xml version="1.0"?> <definitions name="StockQuote" targetNamespace="http://example.com/stockquote.wsdl" xmlns:tns="http://example.com/stockquote.wsdl" xmlns:xsd1="http://example.com/stockquote.xsd" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/"> <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"/> </all> </complexType> </element> <element name="TradePrice"> <complexType> <all> <element name="price" type="float"/> </all> </complexType> </element> </schema> </types> Sample WSDL showing types element

  50. Sample wsdl showing message and portType elements <message name="GetLastTradePriceInput"> <part name="body" element="xsd1:TradePriceRequest"/> </message> <message name="GetLastTradePriceOutput"> <part name="body" element="xsd1:TradePrice"/> </message> <portType name="StockQuotePortType"> <operation name="GetLastTradePrice"> <input message="tns:GetLastTradePriceInput"/> <output message="tns:GetLastTradePriceOutput"/> </operation> </portType>

More Related