Introduction To Web Services: Ioannis G. Baltopoulos
Introduction To Web Services: Ioannis G. Baltopoulos
Ioannis G. Baltopoulos
Ioannis G. Baltopoulos
CORBA (OMG) It is standards-based, vendor-neutral, and language-agnostic. Very powerful but limited however by its complicated way of utilizing the power and exibility of the Internet. DCOM (Microsoft) Distributed Computing platform closely tied to Microsoft component eorts such as OLE, COM and ActiveX. RMI (Sun Microsystems) Java based eort which doesnt play well with other languages. The J2EE platform integrated RMI with IIOP. Web Services (W3C) Web services are more of an evolution than a revolution
Ioannis G. Baltopoulos Introduction to Web Services
Denition A Web Service is a standards-based, language-agnostic software entity, that accepts specially formatted requests from other software entities on remote machines via vendor and transport neutral communication protocols, producing application specic responses. Standards based Language agnostic Formatted requests Remote machines Vendor neutral Transport neutral Application specic responses
Ioannis G. Baltopoulos
Ioannis G. Baltopoulos
The simplest Web service system has two participants: A service producer (provider) A service consumer (requester). The provider presents the interface and implementation of the service, and the requester uses the Web service.
Ioannis G. Baltopoulos
A more sophisticated system: A registry, acts as a broker for Web services. A provider, can publish services to the registry A consumer, can then discover services in the registry
Ioannis G. Baltopoulos
e-Science example
Web Enabled Telescope Access Requirements
In the context of eScience and observatories, there are several requirements from a distributed astronomical system. For example, dierent people need access to subsets of the same data, data needs to be archieved for future use, same functionality implemented using dierent technologies, certain authorities authorize the use of resources, others are responsible for cataloging available resources.
Ioannis G. Baltopoulos
e-Science example
Web Enabled Telescope Access
Ioannis G. Baltopoulos
XML Elements
Formal Denition & Rules
Denition The term element is a technical name for the pairing of a start tag and an end tag in an XML Document.
Production Rule element ::= EmptyElement | STag content ETag STag ::= < Name Attribute > ETag ::= </ Name > EmptyElement ::= < Name Attribute />
XML Elements must be strictly nested! Element names can include letters, the underscore, hyphen and colon; they must begin with a letter. Element names are case sensitive!
Ioannis G. Baltopoulos Introduction to Web Services
XML Elements
Some right & wrong examples
Example <!-- Example 1: Element with two tags --> <message> Welcome! </message> <!-- Example 2: Empty Element (Single tag) --> <message/> Wrong Examples <!-- Example 1: Incorrect Nesting --> <ATag><BTag> Nesting Problem </ATag></BTag> <!-- Example 2: Invalid Element name --> <.wrong.element> some text </.wrong.element>
Ioannis G. Baltopoulos Introduction to Web Services
XML Attributes
Formal Denition & Rules
Denition The term attribute(s) refers to a theoretically arbitrary number of name-value pairs that can be included in the starting tag of an XML element. Production Rule STag ::= < TagName Attribute Attribute ::= AttrName = Value The value part of the attribute has to be quoted. Attribute names starting with xml:are reserved by the XML specication.
Ioannis G. Baltopoulos
>
Processing Instructions
Denition, Rule & Example
Example <!-- Example: A popular one! --> <?xml version="1.0" encoding="UTF-8"?> The PI Target keyword is meaningful to the processing application and hence could be dierent between applications. Everything between the PI Target and the closing question mark is considered the contents of the processing instruction.
Ioannis G. Baltopoulos Introduction to Web Services
Comment A message that helps the human reader understand the program and the processing that takes place at a particular point of the source code. Production Rule Comment ::= <!-- Char --> Character Data Encoding: All characters in an XML document must comply with the documents encoding; those outside the encoding must be escaped and are called character references. Whitespace: Whitespace can be treated as either signicant or insignicant. Most XML applications care little about whitespace. Entities: Like character references, they are predened escape sequences that map to specic characters.
Ioannis G. Baltopoulos Introduction to Web Services
An XML Document
Putting it all together!
<?xml version="1.0" encoding="UTF-8"?> <message from="yiannis" to="family"> <text>Hey, Im at the iCSC! </text> <!-- Attachment is optional --> <attachment> <desc>Photo from Geneva</desc> <item> <?BinaryDataStart ?> 0100100001010001001010010 <?BinaryDataEnd ?> </item> </attachment> </message>
Ioannis G. Baltopoulos
An XML Document consists of: Optional prolog A root element Comments Processing Instructions But...
Some Problems
And how we solved them!
The problems in the previous example relate with the: Physical Structure of the document Well formedness (Parsers) Logical Structure of the document Validity (Schemas). Semantics of the elements? Element Name clashes between Documents Namespaces
Ioannis G. Baltopoulos
XML Namespaces
Motivating the Problem
Solve the problem of recognition and collision of elements in an XML Document. Recognition How does an XML processing application distinguish between the XML elements that describe the message and the XML elements that are part of a Purchase Order? Collision Does the element description refer to attachment descriptions in messages or order item descriptions? Does the item element refer to an item of attachment or an order item?
Ioannis G. Baltopoulos
XML Namespaces
Detailing the Solution
XML Namespaces uses Uniform Resource Identiers for uniquely qualifying local names. As URIs can be long and typically contain characters that arent allowed in XML element names, the process of including namespaces in XML document involved two steps: A namespace identier is associated with a prex, a name that contains only legal XML element name characters with the exception of the colon (;) Qualied names are obtained as a combination of the prex, the colon character, and the local element name Qualified Name = Namespace Identifier + Local Name
Ioannis G. Baltopoulos
XML Namespaces
A couple more last things
Default Namespaces Adding a prex to every element in the document decreases readability and increases document size. Therefore, XML Namespaces allow us to use a default namespace in a document. Elements belonging to the default namespace dont require prexes. Namespace prexed attributes Attributes can also have namespaces associated with them. The desire to extend the information provided by an XML element without having to make changes directly to its document type.
Ioannis G. Baltopoulos
XML Schema
An XML Schema enables the following: Identication of the elements that can be in a document Identication of the order and relation between elements Identication of the attributes of every element and whether theyre optional or required or have some other special properties Identication of the datatype of attribute content Think of it as an elaborate UML Class diagram where classes only have eld and no methods.
Ioannis G. Baltopoulos
Denition SOAP is an industry accepted W3C specication for a ubiquitous XML distributed computing infrastructure.
A mechanism for dening the unit of communication. A mechanism for error handling. An extensibility mechanism Lives above the transport layer of OSI Simply put its a mechanism that allows the transmission of XML documents, regardless of transport layer protocol.
Ioannis G. Baltopoulos Introduction to Web Services
SOAP Messages
Logical & Physical Structure
The root element of a SOAP message is the Envelope element. It contains an optional Header element and the required Body Elements called Faults can be used to describe exceptional situations. It can contain optional Attachments in MIME encoding for exchanging binary data.
Ioannis G. Baltopoulos
SOAP Example
Structure of a real XML SOAP Message
<?xml version="1.0" encoding="UTF-8"?> <soap:Envelope soap:encodingStyle="http://soap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst"> <soap:Header> <!-- Transactions, priorites, etc. --> </soap:Header> <soap:Body> <!-- Some content --> </soap:Body> </soap:Envelope>
Ioannis G. Baltopoulos Introduction to Web Services
The SOAP Message Transmission involves three main roles: The SOAP Sender creates and sends a SOAP Message to an ultimate SOAP Receiver. One or more optional SOAP Intermediaries can be positioned to intercept messages between the the sender and the receiver. They can perform ltering, logging, catching etc. The SOAP senders intended destination is called the Ultimate SOAP Receiver.
Ioannis G. Baltopoulos
A WSDL Document is a set of denitions with a single root element. Services can be dened using the following XML elements:
Types, think Data Type Message, think Methods PortType, think Interfaces Binding, think Encoding Scheme Port, think URL Service, many URLs
Ioannis G. Baltopoulos
PortType Element
Denition and Usage
Denition The portType element describes the interface to a Web Service A WSDL Document can contain zero or more portType A portType element contains a single name attribute. Naming convention nameOfWebService PortType A portType contains one or more operation elements, with a name attribute can contain input, output and fault elements
Ioannis G. Baltopoulos
PortType Element
Example
Example <!-- Port Type Definition Example --> <portType name="weatherCheckPortType"> <operation name="checkTemperature"> <input message="checkTemperatureRequest"/> <output message="checkTemperatureResponse"/> </operation> <operation name="checkHumidity"> <input message="checkHumidityRequest"/> <output message="checkHumidityResponse"/> </operation> </portType>
Ioannis G. Baltopoulos
Message Element
Denition and Usage
Denition A message is a collection of parts; intuitively a part is a named argument with its type. A message is a collection of these parts. A WSDL document can contain zero or more message elements. Each message element can be used as an input, output or fault message within an operation . The type attribute of part can be any standard data type from the XSD Schema or a user dened one.
Ioannis G. Baltopoulos
Message Element
Example
Example <!-- Message Definitions --> <message name="checkTemperatureRequest"> <part name="location" type="xsd:string"> </message> <message name="checkTemperatureResponse"> <part name="result" type="xsd:double"> </message> <message name="checkHumidityRequest"> <part name="location" type="xsd:string"> </message> <message name="checkHumidityResponse"> <part name="result" type="ns:HummidityType" </message>
Ioannis G. Baltopoulos Introduction to Web Services
Types Element
Denition and Usage
Denition Custom user data types dened in an abstract way. The default type system in WSDL is the XML Schema (XSD) A WSDL document can have at most one types element. The types element can contain simpleType or complexType. At the lowest level elements intuitively named (again!) element are dened with a name and a type attribute.
NOTE! The diagram bellow is incomplete! This is considered an advanced topic and for more information you should look at data modelling using the XML Schema.
Ioannis G. Baltopoulos
Types Element
Example
Example <!-- Type Definitions --> <types> <xsd:schema targetNamespace="http://weather.com/ns" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name="HumidityType"> <xsd:sequence> <xsd:element name="loc" type="xsd:string"> <xsd:element name="humd" type="xsd:double"> <xsd:element name="temp" type="xsd:double"> </xsd:sequence> </xsd:complexType> </xsd:schema> </types>
Ioannis G. Baltopoulos Introduction to Web Services
Binding Element
Denition and Usage
Denition The binding element species to the service requester how to format the message in a protocol-specic manner. Each portType can have one or more binding elements associated with it. For a given portType the binding element has to specify an messaging and transport pair. (SOAP/HTTP, SOAP/SMTP, etc).
Ioannis G. Baltopoulos
Binding Element
<binding name="WeatherBinding" type="weatherCheckPortType"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" /> <operation name="checkTemperature"> <soap:operation soapAction="" /> <input> <soap:body use="encoded" namespace="checkTemperature" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </input> <output> <soap:body use="encoded" namespace="checkTemperature" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </output> </operation> </binding>
Ioannis G. Baltopoulos Introduction to Web Services
Port Element
Denition, Usage & Example
Denition The port element species the network address of the endpoint hosting the Web Service.
It associates a single protocol-specic address to an individual binding element. Ports are named and must be unique within the document.
Service Element
Denition and Usage
Denition The service element is a collection of related port elements identied by a single service name. A WSDL Document is allowed to contain multiple service elements, but conventionally contains a single one. Each service must be uniquely named. The naming convention is GeneralInfoService
Ioannis G. Baltopoulos
Service Element
Example
Example <!-- Service definition --> <service name="WeatherCheckService"> <port name="WeatherCheckSOAP" binding="wc:WeatherCheckSOAPBinding"> <soap:address location="http://host/WeatherCheck"/> </port> <port name="WeatherCheckSMTP" binding="wc:WeatherCheckSMTPBinding"> <soap:address location="http://host/WeatherCheck"/> </port> </service>
Ioannis G. Baltopoulos
Concluding Remarks
In this rst lecture we saw the position of Web Services within the Distributed Computing Environment. the XML primitives and touched upon Namespaces and Schemas. how SOAP is used for transferring platform and language independent messages between software entities on dierent hosts. how to describe Web Services using WSDL. ...now...GO FOR COFFEE!
Ioannis G. Baltopoulos