XML and Web Services for Astronomers Roy Williams

XML and Web Services for Astronomers Roy Williams California Institute of Technology roy@caltech. edu Robert Brunner University of Illinois bigdog@uiuc. edu ASASS 2002, 13 October 2002, Baltimore © Roy Williams, Robert Brunner

n XML and Structured Data n XML Syntax n VOTable and other formats n Transformation, Parsing, Binding

What is Markup? <b>Memorandum</b> Markup in a document means extra tags to define the meaning of the text. <hr> From: <i>Antonio Stradivarius</i> To: <i>Domenico Scarlatti</i> Date: 13 April 1723 Rendering Message: Io bisogno una appartamento acoglienti a Cremona … <hr> This markup is HTML Memorandum From: Antonio Stradivarius To: Domenico Scarlatti Date: 13 April 1723 Message: Io bisogno una appartamento acoglienti a Cremona …

Structure with XML <Memo> Separation of structure from presentation <From>Antonio Stradivarius</From> <To>Domenico Scarlatti</To> <Date> <Day>13</Day> Rendering <Month>4</Month> <Year>1723</Year> </Date> 4/13/23 <Body> Io bisogno una appartamento April 13, 1723 acoglienti a Cremona … </Body> 17. iv. 1723 </Memo> Processing The computer can read the document: “Find all memos from April 1723”

Why XML? XML is a standard way to represent structured documents, including metadata and data Platform neutral / Open Vendor supported / Vendor neutral Proven -- decades with SGML Extensible Syntax checking -- Explicit Schema Industry convergence Web friendly

Why XML? • Documents and data • Human readable, editable, mailable • Can encode many data models • Can encode program too • Many tools Parsers in Java, C, C++, Perl, Python, . . . Browsers and editors XML databases Style sheets, formatting, transformation

What is Markup? n Markup is everywhere n Latex, Postscript, FITS, …. n From here we consider only XML dialects: XML VOTable HTML XDF

XML Usage Model SQL Structured Data storage XML XSLT presentation forms queries HTML Interoperability DB Web Services GET, POST, SOAP

Service Workflow Catalog Service Query Check Service Query Estimator Archive Service Crossmatch Service User’s code Archive Service Storage Service SOAP envelopes of XML: VOTable and other VO dialects AND broadband binary

n XML and Structured Data n XML Syntax n VOTable and other formats n Transformation, Parsing, Binding

XML Syntax Start tag Content <From> Antonio Stradivarius </From> Element End tag White space is part of the content -- Many applications ignore it Element names are case-sensitive <From> is not <from>

XML Syntax Empty element: <From/> is equivalent to <From><From/> Note that the HTML constructions and <hr> Are not proper: should be <br/> and <hr/> parent-child <Date> <Day>13</Day> <Month>4</Month> <Year>1723</Year> </Date> One element has no parent Root or Document element siblings

Attributes An attribute is a name-value pair inside the start tag. <From born=“ 1648” died=“ 1737”> Antonio Stradivarius </From> Don’t forget the quotes! Name must be unique in element <From value=“Antonio Stradivarius”/> Can use an empty element with attributes

Element Names can have a-Z 0 -9 _ -. : Colon is reserved for namespaces Names cannot have “ ‘ ` $ ^ % ; <> < > </ > <téléphone> 011 33 91 55 46 23 98 </téléphone> This is good XML

Text in XML Must escape five symbols Symbol escapes < > & “ ‘ This is Greek theta &#x 03 B 8; Fran&#x. E 7; ois not Francois! < > & " ' H < 3 & K > 4 Patrick O' Reilly See http: //www. unicode. org Bulk escape through CDATA <![CDATA[ H<3&K>4 Patrick O’Reilly ]]>

Other stuff Comments <!-- This is a comment --> Processing Instructions <? myprinter color="purple" ? > <? robots ignore="yes" ? > <? xml-stylesheet type="text/xsl" href="http: //us-vo. org/xml/VOTable-basic. xsl"? >

Well-formed XML • Every start tag must have an end tag match • Elements may nest, but not overlap (<a><b>this is wrong</a></b>) • There must be exactly one root element • Attribute values must be quoted • An element cannot have 2 attributes of the same name • No comments inside tags • No unescaped <, >, & in element text or attibute text • Etc etc

Validation (DTD/Xschema) n XML dialects n Applications accept particular types of data – Adobe Illustrator takes Scalable Vector Graphics ML – VO applications take VOTable – Browser takes Platform for Privacy Preferences ML n Validation checks the XML file n Against DTD (Document Type Definition> n Against Xschema n Validation is Optional n Checks if Instance is member of Class

DTD n Inherited from past, not XML n Example from VOTable. dtd <!-- RESOURCEs can contain other RESOURCES, together with TABLEs and other stuff --> <!ELEMENT RESOURCE (DESCRIPTION? , INFO*, COOSYS*, PARAM*, LINK*, TABLE*, RESOURCE*)> <!ATTLIST RESOURCE name CDATA #IMPLIED ID ID #IMPLIED type (results | meta) "results" >

XSchema n XML-based document definition n Elements can be more complex – Type derivation and inheritance n Occurrence constraints • Eg a marriage has exactly two people n Simple data types – For Character data and attributes – string, integer, date. Time, etc – Patterns • Eg a US phone number is xxx-xxxx n Namespaces!

Xschema fragment <!-- RESOURCES can contain DESCRIPTION, (INFO|PARM|LINK), (TABLE|RESOURCE) --> <xs: element name="RESOURCE"> <xs: complex. Type> <xs: sequence> <xs: element ref="DESCRIPTION" min. Occurs="0"/> <xs: element ref="INFO" min. Occurs="0" max. Occurs="unbounded"/> <xs: element ref="COOSYS" min. Occurs="0" max. Occurs="unbounded"/> <xs: element ref="PARAM" min. Occurs="0" max. Occurs="unbounded"/> <xs: element ref="LINK" min. Occurs="0" max. Occurs="unbounded"/> <xs: element ref="TABLE" min. Occurs="0" max. Occurs="unbounded"/> <xs: element ref="RESOURCE" min. Occurs="0" max. Occurs="unbounded"/> </xs: sequence> <xs: attribute name="name" type="xs: token"/> <xs: attribute name="ID" type="xs: ID"/> <xs: attribute name="type" default="results"> <xs: simple. Type> <xs: restriction base="xs: NMTOKEN"> <xs: enumeration value="results"/> <xs: enumeration value="meta"/> </xs: restriction> </xs: simple. Type> </xs: attribute> </xs: complex. Type> </xs: element>

Namespaces “We took the table and chair dimensions, and wrote them in a table. ” Namespace = mydomain. com/furniture Namespace = mydomain. com/word-processing This is a URI (NOT a URL). A URI is a unique string. A URL is an address on the Internet. FITS keywords have no namespace!

Namespaces n For reusing document definitions <furniture: table material="oak"/> <word-processing: table columns="5"/>

Xschema Example <? xml version="1. 0"> <Date> <Day>13</Day> <Month>4</Month> <Year>1723</Year> </Date> Class Instance <? xml version="1. 0"> <xs: schema xmlns: xsd="http: //www. w 3. org/2001/XMLSchema"> <xs: element name="Date"> <xs: complex. Type> <xs: choice> <xs: element name="Day"> <xs: element name="Month"> <xs: element name="Year"> </xs: choice> </xs: complex. Type> </xs: element>

Xschema Example <xs: element name="Day" type="day. Type"> <xs: complex. Type name="day. Type"> <xs: simple. Content> <xs: restriction base="xs: positive. Integer"> <xs: max. Inclusive value="31"/> </xs: restriction> </xs: simple. Content> </xs: complex. Type> <xs: element name="Month" type="month. Type"> <xs: complex. Type name="month. Type"> <xs: simple. Content> <xs: restriction base="xs: NMTOKEN"> <xs: enumeration value="January"/> <xs: enumeration value="February"/> </xs: restriction> </xs: simple. Content> </xs: complex. Type>

n XML and Structured Data n XML Syntax n VOTable and other formats n Transformation, Parsing, Binding

VOTable n VOTable = hierarchy of Metadata + Tables n Metadata = Parameters + Infos + Descriptions + Links + n n Fields Table = list of Fields + Data = stream of Rows Row = list of Cells Cell = Primitive or variable-length list of Primitives n or multidimensional array of Primitives n n Primitive = integer, character, float. Complex, etc

Data in VOTable n Data expressed in XML n <TABLEDATA> <TR><TD> n Or FITS binary table n <FITS><STREAM> n Or BINARY format n simple format, can seek, parallelize n <BINARY><STREAM>

VOTable Stream n STREAM can use different protocols: n <STREAM href="ftp: //server. com/mydata. dat"/> n <STREAM href="ftp: //server. com/mydata. dat" expires="2002 -02 -22"/> n <STREAM href="httpg: //server. com/mydata. dat" actuate="on. Load"/> n <STREAM file="file: ///usr/home/me/mydata. dat"/>

Data in VOTable n Table cell is array of primitives datatype Meaning FITS Bytes "boolean" Logical "L" 1 "bit" Bit "X" * "unsigned. Byte" Byte (0 to 255) "B" 1 "short" Short Integer "int" Integer "I" 2 "J" 4 "long" Long integer "K" 8 "char" ASCII Character "A" 1 "unicode. Char" Unicode Character "float" Floating point 2 "E" 4 "double" Double "D" 8 "float. Complex" Float Complex "C" 8 "double. Complex" Double Complex "M" 16

Metadata in VOTable n Column header == FIELD n Has name, ID, unit, accuracy, etc n Has datatype, arraysize n Has UCD PHOT_INT-MAG_B n ORBIT_ECCENTRICITY n STAT_MEDIAN n INST_QE n Integrated total blue magnitude Orbital eccentricity Statistics Median Value Detector's Quantum Efficiency

VOTable Example <!DOCTYPE VOTABLE SYSTEM "http: //us-vo. org/xml/VOTable. dtd"> <VOTABLE version="1. 0"> <DEFINITIONS> <COOSYS ID="my. J 2000" equinox="2000. " epoch="2000. " system="eq_FK 5"/> </DEFINITIONS> <RESOURCE> <PARAM name="Observer" datatype="char" arraysize="*" value="William Herschel"> <DESCRIPTION>This parameter is designed to store the observer's name </DESCRIPTION> </PARAM> <TABLE name="Stars"> <DESCRIPTION>Some bright stars</DESCRIPTION> <FIELD name="Star-Name" ucd="ID_MAIN" datatype="char" arraysize="10"/> <FIELD name="RA" ucd="POS_EQ_RA" ref="my. J 2000" unit="deg" datatype="float" precision="F 3" width="7"/> <FIELD name="Dec" ucd="POS_EQ_DEC" ref="my. J 2000" unit="deg" datatype="float" precision="F 3" width="7"/> <FIELD name="Counts" ucd="NUMBER" datatype="int" arraysize="2 x 3 x*"/>

VOTable Example <DATA> <TABLEDATA> <TR> <TD>Procyon</TD><TD>114. 827</TD><TD> 5. 227</TD> <TD>4 5 3 4 3 2 1 2 3 3 5 6</TD> </TR> <TD>Vega</TD><TD>279. 234</TD> <TD>38. 782</TD><TD>8 7 8 6</TD> </TR> </TABLEDATA> </DATA> Whitespace separated tokens </TABLE> for array of primitives </RESOURCE> </VOTABLE>

VOTable Example <VOTABLE version="1. 0"> <RESOURCE ID="Stars"> <PARAM ID="Mass" datatype="float" unit="sol. Mass" value="1"/> <RESOURCE ID="Big. Stars"> <PARAM ID="Mass-big" datatype="float" unit="sol. Mass" value="10"/> </RESOURCE> <RESOURCE ID="Small. Stars"> <PARAM ID="Mass-small" datatype="float" unit="sol. Mass" value="0. 2"/> <RESOURCE ID="Very. Small. Stars"> <PARAM ID="Mass-tiny" datatype="float" unit="sol. Mass" value="0. 05"/> </RESOURCE> </VOTABLE>

XDF (NASA Goddard) n N-dimensional blocks n Spatial information n Scalar, vector fields on grid n Tables of multidimensional Spectra with their wavelength scales, images with coordinate axes, vector fields with unit. Direction, data cubes in complicated spaces, tables with column headers, and series of tables with each table having a unique name

XDF Example <XDF> <parameter name="date" > <units><unitless/></units> <value>01 -12 -99</value> </parameter> <structure name="2_vector_spaces"> <array name="Lo. Res"> <units><unit>m/s</unit></units> <axis name="vector components" axis. Id="comps-lo"> <axis. Units><unitless/></axis. Units> <unit. Direction axis. Id. Ref="x-lo" name="x-hat" /> <unit. Direction axis. Id. Ref="y-lo" name="y-hat" /> <unit. Direction axis. Id. Ref="z-lo" name="z-hat" /> </axis> <axis name="x" … <axis name="y" … <axis name="z" …

XDF Example <for axis. Id. Ref="comps-lo"> <for axis. Id. Ref="x-lo"> <for axis. Id. Ref="y-lo"> <for axis. Id. Ref="z-lo"> <ascii. Format> <repeat count="4"> <ascii type="fixed" width="8" precision="3"/> <skip. Char count="1"/> </repeat> <ascii type="fixed" width="8" precision="3"/> </ascii. Format> </for> <data> <![CDATA[ 2432. 2345. 432 2333. 553 5234. 737 5234. 220 5234. 334 5234. 220 2432. 2345. 432 2333. 553 5234. 334 5234. 220. . . ]]></data> </array> </XDF>

AML: Astronomical Markup Language' n Standard exchange format for metadata in astronomy n astronomical n article n table n set of tables n image n person n project object

AML Example <AML> <AOBJECT> <IDENTS> <IDENT> UGC 6 </IDENT> <IDENT> MCG+04 -01 -013 </IDENT> </IDENTS> <COORD coosystem="equatorial"> <RA>000309. 55</RA> <DEC>+215736. 4</DEC> </COORD> <OBJTYPE> Seyfert_2 </OBJTYPE> <MORPHO> Sc </MORPHO> <RADVELO unit="z"> 0. 02226 </RADVELO> <DIM unit="arcmin"> 1. 1 x 0. 8 </DIM> <MAG filter="B"> 14. 62 </MAG> <ORIANGL unit="deg"> 105 </ORIANGL> <REFS> <REF> 1997 Ap. JS. . 108. . 155 G </REF> <REF> 1997 Ap. JS. . 108. . 229 H </REF> </REFS> </AOBJECT> </AML>

n XML and Structured Data n XML Syntax n VOTable and other formats n Transformation, Parsing, Binding

XPath and XSLT n XSL n Extensible Style Language n XSLT n Extensible Style Language Transformation XML document XSLT engine XSL stylesheet Output (HTML, Latex, Excel, . . . )

XSLT example see http: //us-vo. org/VOTable for details

XSLT in the browser <? xml-stylesheet type="text/xsl" href="http: //us-vo. org/xml/VOTable-basic. xsl"? > First line of XML document • ? xml-stylesheet is a processing instruction • Works with Netscape 7 • And IE 6 -- set security to medium-low see http: //us-vo. org/VOTable for details

Building XSLT This document is a stylesheet <xsl: stylesheet version="1. 0" xmlns: xsl="http: //www. w 3. org/1999/XSL/Transform"> When you see this Xpath template <xsl: template match="/memo/date/day"> <h 1> The Memo Day is: <xsl: apply-templates/></h 1> </xsl: template> </xsl: stylesheet> Copy this text Then the text of the relevant element

XML Parsing with SAX: Event-Based Handlers for Start. Element, Text, End. Element, etc. start. Element Memo start. Element From characters Antonio Stradivarius end. Element From start. Element Date start. Element Day characters 13 ….

XML Parsing with SAX try { XMLReader parser = XMLReader. Factory. create. XMLReader(); parser. set. Content. Handler(new my. Handler()); parser. parse("http: //musicalmemos. org/strad. xml"); } catch(SAXParse. Exception e) { // Well-formed error } catch(SAXException e) { // Could not find XMLReader } catch(IOException e) { // could not read file from net }

XML Parsing with SAX public class my. Handler implements Content. Handler { public void start. Element(…, String element. Name, …, Attributes atts){ } public void end. Element(…, String element. Name, …){ } public void characters(char[] test, int start, int length){ } + some other methods… }

XML Parsing with DOM: Document Object Model Returns a tree-like Document object with data attached Memo Body From Antonio Stradivarius Domenico Scarlatti Date To Day Month Year 13 4 1723 Io bisogno una appartamento acoglienti a Cremona …

Parsing XML with DOMParser dp = new DOMParser(); dp. parse(("http: //musicalmemos. org/strad. xml"); Node nd = dp. get. Document(). get. Document. Element(); int count = number. Of. Nodes(nd); public int number. Of. Nodes(Node nd){ int number = 1; Nodelist nl = nd. get. Child. Nodes(); for(int i=0; i<nl. get. Length(); i++) if(nl. item(i). get. Node. Type() == Node. ELEMENT_NODE) number += number. Of. Nodes(nl. item(i)); }

XML Binding n Automatically makes code from DTD/XSchema n eg. Element <Date> generates n get. Day(), set. Day() n get. Month(), set. Month() n get. Year(), set. Year() n Much easier than building it with DOM

XML Binding Votable v = votw. get. Votable(); // just get the first resource -- there may be more that we ignore Resource r = null; if(v. get. Resource. Count() > 0) r = (Resource)v. get. Resource. At(0); else … // just get the first table -- there may be more that we ignore Table table = null; if(r. get. Table. Count() > 0) table = (Table)r. get. Table. At(0); else …

XML Binding n Parsing VOTable n Finding the RA, dec columns by UCD for(int i=0; i<table. get. Field. Count(); i++){ f = (Field)table. get. Field. At(i); String s = f. get. Ucd(); … if(s. equals(“POS_RA_EQ_MAIN”) // this field contains right ascension if(s. equals(“POS_DEC_EQ_MAIN”) // this field contains declination

XML Binding Tools Can use binder from breezefactory. com Also soon JAXB java. sun. com/xml/jaxb/

Web Services for Astronomers n What are Web Services n Web Service Architecture n Building Web Services n The Future of Web Services

What are Web Services? n Web (From Dictionary. com) 1. 2. 3. A latticed or woven structure Something intricately contrived, especially something that ensnares or entangles. A complex, interconnected structure or arrangement Shorthand for the World Wide Web

What are Web Services? n Service (From Dictionary. com) 1. The performance of work or duties for a superior or as a servant 2. An act or a variety of work done for others, especially for pay 3. Assistance; help Slang terms not suitable for print.

What are Web Services? n Web Service n Distributed Computing Model n Self-Contained Modular Applications n Platform Independent n Language Independent Or n An unpaid act of performing intricately contrived work for others that ensnares all?

Hello World public class Hello. World { public java. lang. String get. Message() { return "Hello World!" ; } public static void main(String[] args) { Hello. World hw = new Hello. World() ; System. out. print(hw. get. Message()) ; } }

What are Web Services? A Service that is accessed via the Web!

Who is in Control? n W 3 C (www. w 3 c. org) n WSDL n SOAP/XML Protocol n Web Service Activity n Oasis (www. oasis-open. org) n eb. XML n UDDI n WS-I (www. ws-i. org)

W 3 C Web Services Activity

OASIS

WS-I

How is this different? n RPC Model Exists! n CORBA n COM/DCOM n RMI n… n Web Services use XML!!!!!

Practical Examples n Business to Business n Inventory Records n Bill of Laden n Purchase Orders n Business to Consumer n Financial Data n Spelling/Searching n Product Listings n Airline Reservations


Amazon

Multiple Invocations

Practical Benefits n Programmatic Access n Platform/Language Independent n Compose/Distribute

What about Astronomy n Name Resolution n NED/SIMBAD Models n Image Access n virtualsky n Catalog Access n Intelligent Archive Queries n Catalog Joins n Cross Identification Servers

Cone Search Profiles

SDSS EDR Cone Search

Web Service Paradigm n Service Oriented Programming n Dynamically Locate Services n Services are “ON” the Network n Services can be coupled n Multiple Transport Protocols n HTTP, SMTP, FTP, … n Multiple Message Encodings n SOAP, XML-RPC, XP(? ), …

Web Services for Astronomers n What are Web Services n Web Service Architecture n Building Web Services n The Future of Web Services

Web Service Architecture n Three Primary Roles 1. Service provider 2. Service requester 3. Service broker Broker Provider Requestor

Web Service Architecture n Framework must support 1. 2. 3. Publishing Service Finding a Service Binding a Service

Web Service Lifecycle 1. Service Must be Created 2. Service Must Be Published 3. Service Must be Easily Located 4. Service Must be Invoked/Called 5. Service must be Unpublished

Service Provider n Creates the Service n New Service n Wrap Legacy Service n Wrap “Other” Services n Publishes the Service n Registries n Standard Hierarchies n Supports the Web Service n Unpublishes the Service

Service Broker n Maintains Service Registry n Simplifies Service Location n Categorization n Query Support

Service Requestor n Locates Service n Invokes Service n Direct Request n Indirect Request

The Big Three n Service Description – WSDL n The most important, everything else derives from this n Service Invocation – SOAP Dominant Communication Protocol (XML Protocol) n Service Publication – UDDI Being Pushed Hard, but future not clear. (OGSA)

Describing a Service n Web Services Description Language (WSDL) http: //www. w 3. org/2002/ws/desc/ n XML Document that provides the public interface to a Web Service n n n Public Methods Data Type Information (IN/OUT) Transport Protocol Binding Information Service Location The What, Where, and How!

Invoking a Service n Simple Object Access Protocol (SOAP) n Although as of V 1. 2 SOAP is no longer an acronym http: //www. w 3. org/2000/xp/Group/ n XML protocol for exchanging messages n Platform/Language Independent n Different Transport Protocols (General Case) n HTTP/HTTPR n SMTP n FTP n BEEP n…

Publishing a Service n Universal Description, Discovery, and Integration (UDDI) http: //www. uddi. org (Now under OASIS) n Technical specification for building WSDL document repositories Documents can be published n Document can be searched n Formal Hierarchy n n UDDI Registry implements the specification n IBM, Microsoft, SAP, etc. have public Registries n astrouddi. org (? )

Hello World (WSDL Style) <? xml version="1. 0" encoding="UTF-8"? > <wsdl: definitions target. Namespace="http: //localhost: 8080/axis/Hello. World. jws" xmlns: impl="http: //localhost: 8080/axis/Hello. World. jws" xmlns: intf="http: //localhost: 8080/axis/Hello. World. jws" xmlns: apachesoap="http: //xml. apache. org/xml-soap" xmlns: wsdlsoap="http: //schemas. xmlsoap. org/wsdl/soap/" xmlns: soapenc="http: //schemas. xmlsoap. org/soap/encoding/" xmlns: xsd="http: //www. w 3. org/2001/XMLSchema" xmlns: wsdl="http: //schemas. xmlsoap. org/wsdl/" xmlns="http: //schemas. xmlsoap. org/wsdl/"> <wsdl: types> <schema xmlns="http: //www. w 3. org/2001/XMLSchema" target. Namespace="http: //localhost: 8080/axis/Hello. World. jws"> <import namespace="http: //schemas. xmlsoap. org/soap/encoding/"/> <complex. Type name="Array. Of_xsd_string"> <complex. Content> <restriction base=" soapenc: Array"> <attribute ref="soapenc: array. Type" wsdl: array. Type="xsd: string[]"/> </restriction> </complex. Content> </complex. Type> <element name="Array. Of_xsd_string" nillable="true" type="impl: Array. Of_xsd_string"/> </schema> </wsdl: types> <wsdl: message name="main. Request"> <wsdl: part name="args" type="impl: Array. Of_xsd_string"/> </wsdl: message> <wsdl: message name="get. Message. Response"> <wsdl: part name="get. Message. Return" type="xsd: string"/> </wsdl: message> <wsdl: message name="get. Message. Request"> </wsdl: message> <wsdl: message name="main. Response"> </wsdl: message> <wsdl: port. Type name="Hello. World"> <wsdl: operation name="main" parameter. Order ="args"> <wsdl: input name="main. Request" message="impl: main. Request"/> <wsdl: output name="main. Response" message="impl: main. Response"/> </wsdl: operation> <wsdl: operation name="get. Message"> <wsdl: input name="get. Message. Request" message="impl: get. Message. Request"/> <wsdl: output name="get. Message. Response" message="impl: get. Message. Response"/> </wsdl: operation> </wsdl: port. Type> <wsdl: binding name="Hello. World. Soap. Binding" type="impl: Hello. World"> <wsdlsoap: binding style="rpc" transport="http: //schemas. xmlsoap. org/soap/http"/> <wsdl: operation name="main"> <wsdlsoap: operation soap. Action=""/> <wsdl: input name="main. Request"> <wsdlsoap: body use="encoded" encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/" namespace="http: //localhost: 8080/axis/Hello. World. jws"/> </wsdl: input> <wsdl: output name="main. Response"> <wsdlsoap: body use="encoded" encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/" namespace="http: //localhost: 8080/axis/Hello. World. jws"/> </wsdl: output> </wsdl: operation> <wsdl: operation name="get. Message"> <wsdlsoap: operation soap. Action=""/> <wsdl: input name="get. Message. Request"> <wsdlsoap: body use="encoded" encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/" namespace="http: //localhost: 8080/axis/Hello. World. jws"/> </wsdl: input> <wsdl: output name="get. Message. Response"> <wsdlsoap: body use="encoded" encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/" namespace="http: // localhost: 8080/axis/Hello. World. jws"/> </wsdl: output> </wsdl: operation> </wsdl: binding> <wsdl: service name="Hello. World. Service"> <wsdl: port name="Hello. World" binding="impl: Hello. World. Soap. Binding"> <wsdlsoap: address location="http: // localhost: 8080/axis/Hello. World. jws"/> </wsdl: port> </wsdl: service> </wsdl: definitions>

WSDL Definitions Element <? xml version="1. 0" encoding="UTF-8"? > <wsdl: definitions target. Namespace="http: //localhost: 8080/axis/Hello. World. jws" xmlns: impl="http: //localhost: 8080/axis/Hello. World. jws" xmlns: intf="http: //localhost: 8080/axis/Hello. World. jws" xmlns: apachesoap="http: //xml. apache. org/xml-soap" xmlns: wsdlsoap="http: //schemas. xmlsoap. org/wsdl/soap/" xmlns: soapenc="http: //schemas. xmlsoap. org/soap/encoding/" xmlns: xsd="http: //www. w 3. org/2001/XMLSchema" xmlns: wsdl="http: //schemas. xmlsoap. org/wsdl/" xmlns="http: //schemas. xmlsoap. org/wsdl/"> … </wsdl: definitions>

WSDL Document Elements n <wsdl: types> The datatypes used by the Web Service n <wsdl: message> The abstract definition of the data being transmitted n <wsdl: port. Type> The abstract operations that constitute the Web service n <wsdl: binding> The concrete protocol and data format used by the Web service n <wsdl: port> The address for a single communication endpoint n <wsdl: service> An aggregation of related ports

WSDL Types n Define the datatypes used as arguments to the Web service as well as the return values from a Web service n Preferably XML Schema n XSD namespace n Must Handle nillable (Java Wrapper Classes) n SOAP

WSDL Types n Map WSDL (XSD) to Language (e. g. , Java) xsd: boolean xsd: byte xsd: double xsd: float xsd: int xsd: long xsd: short xsd: date. Time java. util. Calendar xsd: decimal java. math. Big. Decimal xsd: hex. Binary byte[] xsd: base 64 Binary byte[] xsd: QName javax. xml. namespace. QName xsd: integer java. math. Big. Integer xsd: string java. lang. String

WSDL Types n Recommended approach n Use Elements not Attributes n Only define types that refer to abstract content of messages (not protocols) n Array types should extend the SOAP Array type n Name scheme: Array. Of. XXX n Xsd: any. Type used to represent any type.

<wsdl: types> <schema xmlns="http: //www. w 3. org/2001/XMLSchema" target. Namespace="http: //localhost: 8080/axis/Hello. World. jws"> <import namespace="http: //schemas. xmlsoap. org/soap/encoding/"/> <complex. Type name="Array. Of_xsd_string"> <complex. Content> <restriction base="soapenc: Array"> <attribute ref="soapenc: array. Type" wsdl: array. Type="xsd: string[]"/> </restriction> </complex. Content> </complex. Type> <element name="Array. Of_xsd_string" nillable="true" type="impl: Array. Of_xsd_string"/> </schema> </wsdl: types>

Web service Messages n Interactions between Web service client and server are called messages n Message element describes the messages that can be exchanged n Logical definition of a type of message that may be used by operations listed in port. Type element Input n Output n Fault Message n n Components n Message must have a local name

Web service Messages n Components (wsdl: message element) n Message must have a local name n Use WSDL Namespace n Zero or more Part descriptions n n part name part type Arguments or return parameters. Should follow XML Schema n Message element Future?

<wsdl: message> <wsdl: message name="main. Request"> <wsdl: part name="args" type="impl: Array. Of_xsd_string"/> </wsdl: message> <wsdl: message name="get. Message. Response"> <wsdl: part name="get. Message. Return" type="xsd: string"/> </wsdl: message> <wsdl: message name="get. Message. Request"> </wsdl: message> <wsdl: message name="main. Response"> </wsdl: message>

WSDL Port Types WSDL defines four transmission primitives (or operations) that an endpoint can support § One-way (input element) § § Request-response (input then output element) § § The endpoint receives a request, and sends a correlated response. Solicit-response (output then input element) § § The endpoint receives a request, but does not send a response. The endpoint sends a response, and receives a correlated response. Notification (output element) § The endpoint sends a response, but does not receive a request.

WSDL port. Type § A port. Type element defines the interfaces that a Web service exposes. § Similar to a Class § Module § or Function Library § § The operations are the class/module/library methods.

<wsdl: port. Type> <wsdl: port. Type name="Hello. World"> <wsdl: operation name="main" parameter. Order="args"> <wsdl: input name="main. Request" message="impl: main. Request"/> <wsdl: output name="main. Response" message="impl: main. Response"/> </wsdl: operation> <wsdl: operation name="get. Message"> <wsdl: input name="get. Message. Request" message="impl: get. Message. Request"/> <wsdl: output name="get. Message. Response" message="impl: get. Message. Response"/> </wsdl: operation> </wsdl: port. Type>

WSDL Binding n Defines message format n For a given port. Type, defines protocol n for operations n for messages n Requires unique name attribute n Type attribute is port. Type Qname

<wsdl: binding> <wsdl: binding name="Hello. World. Soap. Binding" type="impl: Hello. World"> <wsdlsoap: binding style="rpc" transport="http: //schemas. xmlsoap. org/soap/http"/> … <wsdl: operation name="get. Message"> <wsdlsoap: operation soap. Action=""/> <wsdl: input name="get. Message. Request"> <wsdlsoap: body use="encoded" encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/" namespace="http: //localhost: 8080/axis/Hello. World. jws"/> </wsdl: input> <wsdl: output name="get. Message. Response"> <wsdlsoap: body use="encoded" encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/" namespace="http: //localhost: 8080/axis/Hello. World. jws"/> </wsdl: output> </wsdl: operation> </wsdl: binding>

WSDL Services n A port defines a single endpoint n The port can then be used for binding n Multiple ports can reference the same address with different protocols n A Service consists of one or more ports n A service defines a single service. Type

<wsdl: service> & <wsdl: port> <wsdl: service name="Hello. World. Service"> <wsdl: port name="Hello. World" binding="impl: Hello. World. Soap. Binding"> <wsdlsoap: address location="http: //localhost: 8080/axis/Hello. World. jws"/> </wsdl: port> </wsdl: service>

Invoking a Service n Use SOAP to communicate messages n SOAP Sender to SOAP Receiver n Potential SOAP Intermediaries n Essentially a one-way communication between SOAP nodes. n RPC style n Document style

SOAP Basics n Message is wrapped in the Envelope n Envelope consists of n Header (Optional) used by intermediaries n Body contains the actual message n n Document Service Call n Fault Handling n Child element of body n Contains Reason and Code elements

SOAP Basics n Fault Handling (V 1. 2) n Fault Element is a child element of body n No other elements in the body n Contains n Reason element (Mandatory) n Code element (Mandatory) – Standard List n Detail element (Optional) n Node element (Optional) n Role element (Optional)

SOAP Request (Hello. World) POST /axis/Hello. World. jws HTTP/1. 0 Content-Type: text/xml; charset=utf-8 Accept: application/soap+xml, application/dime, multipart/related, text/* User-Agent: Axis/1. 0 Host: localhost Cache-Control: no-cache Pragma: no-cache SOAPAction: "" Content-Length: 407 <? xml version="1. 0" encoding="UTF-8"? > <soapenv: Envelope xmlns: soapenv="http: //schemas. xmlsoap. org/soap/envelope/" xmlns: xsd="http: //www. w 3. org/2001/XMLSchema" xmlns: xsi="http: //www. w 3. org/2001/XMLSchema-instance"> <soapenv: Body> <ns 1: get. Message soapenv: encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/" xmlns: ns 1="http: //localhost: 8080/axis/Hello. World. jws"/> </soapenv: Body> </soapenv: Envelope>

SOAP Response (Hello. World) HTTP/1. 1 200 OK Content-Type: text/xml; charset=utf-8 Connection: close Date: Wed, 09 Oct 2002 21: 34: 47 GMT Server: Apache Tomcat/4. 0. 6 (HTTP/1. 1 Connector) Set-Cookie: JSESSIONID=8 A 6802 F 3136 B 882 A 53 BC 0 E 8 E 1 E 30 F 8 CC; Path=/axis <? xml version="1. 0" encoding="UTF-8"? > <soapenv: Envelope xmlns: soapenv="http: //schemas. xmlsoap. org/soap/envelope/" xmlns: xsd="http: //www. w 3. org/2001/XMLSchema" xmlns: xsi="http: //www. w 3. org/2001/XMLSchema-instance"> <soapenv: Body> <ns 1: get. Message. Response soapenv: encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/" xmlns: ns 1="http: //localhost: 8080/axis/Hello. World. jws"> <get. Message. Return xsi: type="xsd: string">Hello World!</get. Message. Return> </ns 1: get. Message. Response> </soapenv: Body> </soapenv: Envelope>

Web Service Registries n UDDI Currently Dominant n Public Registries n IBM, MS, SAP, etc. Private Registries n UDDI Functions n n Describe services Discover businesses Integrate business services n The Meta. Data Problem

UDDI Registry n Business n Can have multiple Services n Business n Has Entity Service an associated specification n Specification n Detailed n Service Pointers information on service Types n Defined by a t. Model n t. Model and WSDL

UDDI Registry

UDDI Private Registry n Some development tools or products provide private UDDI registry server n Java WS Developer pack. n Oracle JDeveloper n IBM WS toolkit n MS VS. NET n Greater control, no registration!

Web Services for Astronomers n What are Web Services n Web Service Architecture n Building Web Services n The Future of Web Services

Building Web Services n Simple Demonstration of Deploying a Web service n Use Java (but other options exist: . NET, Perl, python, etc. )

Tomcat Server

AXIS SOAP Server

Installation & Setup n Install Tomcat n Deploy Axis web apps into Tomcat webapps directory. n Start Tomcat Server n Validate AXIS Installation

Web Service Deployment n Simple Technique (JWS) n Copy Java Source file containing the method(s) to be exposed to axis directory n Hello. World. java -> Hello. World. jws n Complex Technique (WSDD) n AXIS solution n Web Service Deployment Descriptor n Annotations (. NET approach) n [Web. Method]

Hello World (Java) public class Hello. World { public java. lang. String get. Message() { return "Hello World!" ; } }

Hello World (CSharp) using System. Web. Services ; public class Hello. World : Web. Service { [Web. Method] public string get. Message() { return "Hello World!" ; } }

View WSDL

Web Service Client n Generate Client Stub from WSDL n wsdl 2 java tool included with AXIS >java org. apache. axis. wsdl. WSDL 2 Java http: //localhost: 8080/axis/Hello. World. jws? wsdl n Generates n n localhostHello. World. java localhostHello. World. Service. Locator. java localhostHello. World. Soap. Binding. Stub. java

Utilizing the Stub Classes n Hello. World. Client. java package localhost ; public class Hello. World. Client { public static void main(String[] args) throws Exception { // Make a service Hello. World. Service service = new Hello. World. Service. Locator(); // Now use the service to get a stub Hello. World port = service. get. Hello. World(); System. out. println(port. get. Message()); } }

AXIS Extras n Generate Server Skeleton Stub from WSDL >java org. apache. axis. wsdl. WSDL 2 Java –s http: //localhost: 8080/axis/Hello. World. jws? wsdl n Generates n localhostHello. World. Soap. Binding. Impl. java n More arguments for additional functionality

AXIS TCP Monitor

Web Services for Astronomers n What are Web Services n Web Service Architecture n Building Web Services n The Future of Web Services

Roadblocks or Speedbumps? n Reliable Protocol Needed (HTTPR, BEEP) n Lack of State n Implementation Inconsistencies n unsigned n multipart/structures n Security!

Reliable Protocols n HTTP – Reliable HTTP n IBM Initiative http: //www-106. ibm. com/developerworks/library/ws-phtt/ n Adds Persistence to HTTP n BEEP (Blocks Extensible Exchange Protocol http: //www. ietf. org/rfc 3080. txt n Connection-oriented n Asynchronous interactions

DIME (Direct Internet Message Encapsulation) n General purpose binary message format n Enable Web services to efficiently handle multiple attachments Encrypted messages n Graphics n Multimedia content n General Documents n n DIME Message (application/dime) n 1+ records to deliver payload n Chunking http: //www. ietf. org/internet-drafts/draft-nielsen-dime-02. txt

BPEL 4 WS n Business Process Execution Language for Web Services Implementing executable business processes. n Describing non-executable abstract processes. n n Merging of WSFL and Xlang n Ugliest WS Acronym award n Define new Web service as a composition of existing Web services

Simplify Development/Deployment

J 2 EE Web Services n Java APIs for XML n JAX-RPC n JAXM (SAAJ) n JAXR n JSR 109 - Implementing Enterprise Web Services n JSR 110 - Java APIs for WSDL

Security n Issues include n Message Integrity n Message Confidentiality n Authentication n Technologies include n Secure Sockets Layer (SSL) n Transport Layer Security (TLS) n Message Encryption n Digital Signatures n But Standards !!!!!

Summary n Web services provide a powerful programming paradigm n Mucho Hype n Looking for Real Applications (NVO) n Open Grid Services Architecture (OGSA)
- Slides: 132