460 likes | 483 Views
This lecture discusses the basics of web services and XML, including SOAP, WSDL, UDDI, and the benefits of using web services in distributed computing systems.
E N D
EEC-681/781Distributed Computing Systems Lecture 7 Wenbing Zhao wenbing@ieee.org (Lecture nodes are based on materials obtained from http://www.w3schools.com)
Outline • Introduction to Web services • XML, SOAP, WSDL, UDDI • Reminder: • Midterm #1: Oct 8, 6-8pm EEC-681: Distributed Computing Systems
Web Services • Web services are application components • Web services communicate using open protocols • Web services are self-contained and self-describing • Web services can be discovered using UDDI • Web services can be used by other applications • XML is the basis for Web services • Focuses on messages and documents, not on APIs EEC-681: Distributed Computing Systems
How Does it Work? • The basic Web services platform is XML + HTTP • The HTTP protocol is the most used Internet protocol • XML provides a language which can be used between different platforms and programming languages and still express complex messages and functions EEC-681: Distributed Computing Systems
Web Services Platform Elements • SOAP (Simple Object Access Protocol) • WSDL (Web Services Description Language) • UDDI (Universal Description, Discovery and Integration) EEC-681: Distributed Computing Systems
Why Web Services? • Enables maximum interoperability of Web applications • Based on standard: SOAP, WSDL, UDDI • Requires minimum infrastructure • Shorter learning curve, easier to maintain • Highly extensible and very low level of application integration • Enable adaptable and upgradeable apps EEC-681: Distributed Computing Systems
What is XML? • XML is a text-based Extensible Markup Language • Similar to HTML, an XML file consists of tags, i.e., identifiers enclosed in angle brackets <…> • XML tags identify data only, it does not specify how to display it (start) tag <message> <to>you@yourAddress.com</to> <from>me@myAddress.com</from> <subject>XML Is Really Cool</subject> <text> How many ways is XML cool? ...</text> </message> (end) tag EEC-681: Distributed Computing Systems
XML Syntax • Element: A unit of XML data, delimited by tags • An XML element can enclose other elements • Attribute: A tag can contain attributes. An attribute is A qualifier on an XML tag that provides additional information • For example, in the tag <slide title="My Slide">, title is an attribute, and My Slide is its value <message to="you@yourAddress.com"from="me@myAddress.com"subject="XML Is Really Cool"> <text> How many ways is XML cool? ... </text> </message> Element EEC-681: Distributed Computing Systems
XML Syntax • Empty tag: an element with no data value • <flag/> is equivalent to <flag></flag> • An XML document must be well-formed, i.e. for each tag, there must be a corresponding end tag, unless it is an empty tag • Comment: same as HTML comment • <!-- This is a comment --> • Prolog: each XML document must have a prolog preceding XML data. A prolog contains a declaration and an optional DTD • <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?> EEC-681: Distributed Computing Systems
XML Syntax • Document Type Definition (DTD): specifies • The kinds of tags that can be included in the XML document, and • The valid arrangements of those tags • There are many alternatives to DTD, such as XML Schema EEC-681: Distributed Computing Systems
Why XML • Extensibility • Self describing structured data • Support hierarchical structure • Easy to edit and debug • Easy to process • Separation of data and formatting information (not relevant to Web Services) EEC-681: Distributed Computing Systems
Processing XML Document • An XML document can be accessed either serially or in random access mode • Simple API for XML (SAX) • Serial access and event driven • Document Object Model (DOM) • Convert XML document into a collection of objects, allows random access and modification EEC-681: Distributed Computing Systems
What is SOAP? • SOAP stands for Simple Object Access Protocol • SOAP is a communication protocol • SOAP is for communication between applications • SOAP is a format for sending messages • SOAP is designed to communicate via Internet • SOAP is platform independent • SOAP is language independent • SOAP is based on XML • SOAP is simple and extensible • SOAP allows you to get around firewalls EEC-681: Distributed Computing Systems
Why SOAP? • SOAP is designed specifically to enable applications to communicate over Internet • SOAP runs on top of HTTP and other protocols such as SMTP and FTP • Older middleware-level protocols, such as CORBA and DCOM, are not designed for to run on HTTP • Firewalls are not friendly to such messages EEC-681: Distributed Computing Systems
SOAP Envelope SOAPheader Header Block Body Block SOAPBody SOAP Building Blocks • A SOAP message is an XML document containing the following elements: • A requiredEnvelope element that identifies the XML document as a SOAP message • An optionalHeader element that contains header information • A requiredBody element that contains call and response information • An optionalFault element that provides information about errors that occurred while processing the message EEC-681: Distributed Computing Systems
SOAP Syntax Rules • A SOAP message • MUST be encoded using XML • MUST use the SOAP Envelope namespace • MUST use the SOAP Encoding namespace • Must NOT contain a DTD reference • Must NOT contain XML Processing Instructions EEC-681: Distributed Computing Systems
Skeleton SOAP Message <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope“ soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <soap:Header> … … </soap:Header> <soap:Body> ... ... <soap:Fault> ... ... </soap:Fault> </soap:Body> </soap:Envelope> EEC-681: Distributed Computing Systems
SOAP Envelope Element • It is required and it is the root element of a SOAP message • It defines the XML document as a SOAP message • It must specify the mandatory namespace <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope“ soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding"> … Message information goes here … </soap:Envelope> • The SOAP encodingStyle attribute is used to define the data types used in the document EEC-681: Distributed Computing Systems
SOAP Namespace • Most elements in a soap message are required to be namespace-qualified in the form ns:tag • You need to define the namespace only once in a message <soap:Envelope xmlns:soap=http://schemas.xmlsoap.org/soap/envelope> namespace Namespace definition (SOAP default namespace) <soapenv:Envelopexmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope> It doesn’t matter what name you use EEC-681: Distributed Computing Systems
SOAP Header Element • The SOAP Header element is optional • The header element contains application specific information about the SOAP message • E.g. authentication, coordination, etc. • If the Header element is present, it must be the first child element of the Envelope element EEC-681: Distributed Computing Systems
SOAP Header Element • The actor attribute • It is used to address the Header element to a particular endpoint along the message path • The mustUnderstand attribute • It is used to indicate whether a header entry is mandatory or optional for the recipient to process EEC-681: Distributed Computing Systems
SOAP Body Element • It is required • It contains actual SOAP message intended for the ultimate endpoint of the message • Immediate child elements of the SOAP Body element may be namespace-qualified • SOAP defines the Fault element inside the Body element in the default namespace EEC-681: Distributed Computing Systems
SOAP Fault Element • The Fault element (if present) carries an error message • If present, it is embedded in the Body element as a child element • A Fault element can only appear once in a SOAP message EEC-681: Distributed Computing Systems
SOAP Fault Element • The SOAP Fault element has the following sub elements EEC-681: Distributed Computing Systems
SOAP Fault Element • SOAP Fault Codes EEC-681: Distributed Computing Systems
HTTP Protocol • HTTP communicates over TCP/IP • An HTTP client connects to an HTTP server using TCP • After establishing a connection, the client can send an HTTP request message to the server: POST /item HTTP/1.1 Host: 137.148.142.239 Content-Type: text/plain Content-Length: 200 EEC-681: Distributed Computing Systems
HTTP Protocol • The server then processes the request and sends an HTTP response back to the client • The response contains a status code that indicates the status of the request: • In the example above, the server returned a status code of 200. This is the standard success code for HTTP • If the server could not decode the request, it could have returned something like this: 200 OK Content-Type: text/plain Content-Length: 200 400 Bad Request Content-Length: 0 EEC-681: Distributed Computing Systems
HTTP POST SOAP Envelope SOAPheader Transactional context SOAPBody Name of Procedure Input parameter 1 Input parameter 2 SOAP HTTP Binding • A SOAP method call is an HTTP request/response that complies with SOAP encoding rules • HTTP + XML = SOAP • A SOAP request could be an HTTP POST or an HTTP GET request • The HTTP POST request specifies at least two HTTP headers: • Content-Type and Content-Length EEC-681: Distributed Computing Systems
SOAP HTTP Binding • Content-Type header: defines the MIME type for the SOAP message and the character encoding (optional) used for the XML body of the request or response • Syntax: • Example: Content-Type: MIMEType; charset=character-encoding POST /item HTTP/1.1 Content-Type: application/soap+xml; charset=utf-8 MIME : Multipurpose Internet Mail Extensions EEC-681: Distributed Computing Systems
SOAP HTTP Binding • Content-Length header: specifies the number of bytes in the body of the request or response • Syntax: • Example: Content-Length: bytes POST /item HTTP/1.1 Content-Type: application/soap+xml; charset=utf-8 Content-Length: 250 EEC-681: Distributed Computing Systems
What is WSDL? • WSDL stands for Web Services Description Language • WSDL is written in XML • WSDL is an XML document • WSDL is used to describe Web services • WSDL is also used to locate Web services EEC-681: Distributed Computing Systems
WSDL Document Structure • A WSDL document describes a web service using these major elements: Service Port (e.g. http://host/svc) Port Binding (e.g. SOAP) Binding Abstract interface portType operation(s) inMesage outMessage EEC-681: Distributed Computing Systems
WSDL Ports • The <portType> element describes a web service • The operations that can be performed, and • The messages that are involved • It can be compared to a function library (or a class) in a traditional programming language <portType name="GetQuote"> <operation name="getQuote" > <input message="tns:GetQuoteRequest"/> <output message="tns:GetQuoteResponse"/> </operation> </portType> EEC-681: Distributed Computing Systems
WSDL Messages • The <message> element defines the data elements of an operation • Each message can consist of one or more parts • The parts can be compared to the parameters of a function call in a traditional programming language <message name="GetQuoteRequest"> <part name="symbol" type="xsd:string"/> </message> <message name="GetQuoteResponse"> <part name="result" type="xsd:float"/> </message> EEC-681: Distributed Computing Systems
WSDL Types • The <types> element defines the data type used by the web service • For maximum platform neutrality, WSDL uses XML Schema syntax to define data types <wsdl:types> <xs:schema> <xs:import namespace='http://schemas.xmlsoap.org/ws/2004/08/addressing' schemaLocation='addr.xsd' /> </xs:schema> </wsdl:types> EEC-681: Distributed Computing Systems
WSDL Ports – Operation Types • WSDL defines four operation types EEC-681: Distributed Computing Systems
One-Way Operation <message name="newTermValues"> <part name="term" type="xs:string"/> <part name="value" type="xs:string"/> </message> <portType name="glossaryTerms"> <operation name="setTerm"> <input name="newTerm" message="newTermValues"/> </operation> </portType > Input only EEC-681: Distributed Computing Systems
Request-Response Operation <message name="getTermRequest"> <part name="term" type="xs:string"/> </message> <message name="getTermResponse"> <part name="value" type="xs:string"/> </message> <portType name="glossaryTerms"> <operation name="getTerm"><input message="getTermRequest"/> <output message="getTermResponse"/> </operation></portType> Input and output EEC-681: Distributed Computing Systems
WSDL Bindings • WSDL bindings (<binding> element) defines the message format and protocol details for a web service • Many different bindings are defined: SOAP, HTTP and MIME EEC-681: Distributed Computing Systems
Binding to SOAP <binding type="glossaryTerms" name="b1"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> <operation> <soap:operation soapAction="http://example.com/getTerm"/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> </binding> EEC-681: Distributed Computing Systems
Binding to SOAP • Thebinding element has two attributes: • Name attribute (you can use any name you want) defines the name of the binding • Type attribute points to the port for the binding, in this case the "glossaryTerms" port <binding type="glossaryTerms" name="b1"> EEC-681: Distributed Computing Systems
Binding to SOAP • The soap:binding element has two attributes: • Style attribute can be "rpc" or "document" • Transport attribute defines the transport protocol to use <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> EEC-681: Distributed Computing Systems
Binding to SOAP <operation> <soap:operation soapAction="http://example.com/getTerm"/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> • Theoperation element defines each operation that the port exposes • You must define a SOAP action for each operation • You must also specify how the input and output are encoded Literal encoding: uses a XML Schema to validate SOAP data EEC-681: Distributed Computing Systems
UDDI • Universal Description, Discovery and Integration (UDDI) is a directory service where businesses can register and search for Web services • UDDI uses WSDL to describe interfaces to web services • UDDI communicates via SOAP EEC-681: Distributed Computing Systems
UDDI Benefits • Describing services and business processes programmatically in a single, open, and secure environment • Making it possible to discover the right business from the millions currently online • Reaching new customers and increasing access to current customers • Allowing for rapid participation in the global Internet economy EEC-681: Distributed Computing Systems
References • XML: http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/index.html • SOAP: http://www.w3schools.com/soap/default.asp • WSDL and UDDI:http://www.w3schools.com/wsdl/default.asp EEC-681: Distributed Computing Systems