web services n.
Skip this Video
Loading SlideShow in 5 Seconds..
Web Services PowerPoint Presentation
Download Presentation
Web Services

Web Services

317 Views Download Presentation
Download Presentation

Web Services

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Web Services Index • Overview • SOAP • WSDL • UDDI • Performance basado en UPC-DAC/FIB-AAD Jordi Torres; v2.0-05/04

  2. Web Services • What are web services? • Web services are modular web applications that provide data and services to other applications over the web • Web services apply web technologies such as HTTP and XML to the concepts of distributed computing technologies such as CORBA and DCOM • Aplicaciones auto-contenidas, auto-escritas que pueden ser publicadas, localizadas e invocadas a través de la Web

  3. Web Service Examples • A stock quote service. • A weather service, a map service, a web search service… • any composition of Web services. • e.g. Dollar Rent-A-Car • Create standard interfaces so business partners could tap into the company's car reservation system. • Google, Amazon, … 

  4. What are Web Services? • Today’s web: • Web designed for application to human interactions • Information sharing: a distributed content library. • Built on very few standards: http + html • Shallow interaction model: very few assumptions made about computing platforms. • Enabled B2C e-commerce. • Non-automated B2B interactions. • “Web services” is an effort to build a distributed computing platform for the Web. • Services available via the Web. • Meant mainly for application to application communication (as opposed to users directly) Enables Business-to-Business transactions. • E.g., a web service is contacted on a URL using the SOAP protocol over HTTP.

  5. Complete picture of distributed applications (using WS)

  6. Core technologies used for WS • XML • SOAP • Simple Object Access Protocol • a framework for exchanging XML-based information in a network • the currently most hyped XML/Web service technology • WSDL • Web Service Description Language • an XML-based language for describing network services • WSDL descriptions of capabilities and locations of services • like an interface description language for Web services • communication using SOAP or direct HTTP • UDDI • Universal Description, Discovery, and Integration • provides a registry mechanism for clients and servers to find each other • uses SOAP for communication

  7. Otra definición • Programas accesibles en Internet que exponen su funcionalidad recibiendo/enviando mensajes SOAP a través de HTTP(s) y describen su interfaz en WSDL

  8. The Web Services Stack ServicePublication/Discovery UDDI ServiceDescription WSDL XML Messaging SOAP Transport Network HTTP, SMTP, MQSeries, etc.

  9. What is SOAP? • SOAP is a lightweight protocol for exchange of information in a decentralized, distributed environment using XML.

  10. The Simple Object Access Protocol (SOAP) • XML-based protocol for messaging and RPC • Can works on top of existing transports • HTTP, SMTP, FTP, MQSeries • Use of XML schema for encoding typed values • Language independent • Generation of SOAP messages available in popular programming language • C, Java, Perl

  11. SOAP: FORMATO GENERAL Envelope Header Header Key Header Key Body

  12. SOAP: Formato general • SOAP especifica el formato de mensajes Envelope: datos globales (codificación, espacio de nombres, ...) contiene: header (opcional) + body (obligatorio) Body:contiene datos en formato XML Header: contiene meta-informaticón

  13. Sample HTTP Interaction (C) Prof. Dr. Frank Leymann, IBM

  14. HTTP POST: Invoking Code (C) Prof. Dr. Frank Leymann, IBM

  15. A Simple SOAP RPC ( SOAP Message Embedded in HTTP Request) POST /StockQuote HTTP/1.1Host: www.stockquoteserver.comContent-Type: text/xml; charset="utf-8"Content-Length: nnnnSOAPAction: "Some-URI"<SOAP-ENV:Envelope  xmlns:SOAP-ENV=""  SOAP-ENV:encodingStyle="">   <SOAP-ENV:Body>       <m:GetLastTradePrice xmlns:m="Some-URI">           <symbol>DIS</symbol>       </m:GetLastTradePrice>   </SOAP-ENV:Body></SOAP-ENV:Envelope> Object Endpoint Method name Input parameter

  16. A simple soap response ( SOAP Message Embedded in HTTP Response) HTTP/1.1 200 OKContent-Type: text/xml; charset="utf-8"Content-Length: nnnn<SOAP-ENV:Envelope  xmlns:SOAP-ENV=""  SOAP-ENV:encodingStyle=""/>   <SOAP-ENV:Body>       <m:GetLastTradePriceResponse xmlns:m="Some-URI">           <Price>34.5</Price>       </m:GetLastTradePriceResponse>   </SOAP-ENV:Body></SOAP-ENV:Envelope>

  17. (three) standard aspects of SOAP • Overall message format A SOAP message is an envelope containing zero or more headers and exactly one body. • The SOAP encoding rules defines a serialization mechanism that can be used to exchange instances of application-defined datatypes. ( based on XSD) • The SOAP RPC representation defines a convention that can be used (optional) to represent remote procedure calls and responses (if not, message-oriented style)

  18. Working example: A soap request POST /servlet/rpcrouter HTTP/1.1 Host: Content-Type: text/xml; charset="utf-8" Content-Length: nnnn SOAPAction: "" <SOAP-ENV:Envelope xmlns:SOAP-ENV="" <SOAP-ENV:Body> <ns1:getMessage xmlns:ns1="urn:NextMessage" SOAP-ENV:encodingStyle=""> <UserID xsi:type="xsd:string">JDoe</UserID> <Password xsi:type="xsd:string">0JDOE0</Password> </ns1:getMessage> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

  19. Working example: soap response HTTP/1.1 200 OK Content-Type: text/xml; charset="utf-8" Content-Length: nnnn <SOAP-ENV:Envelope> xmlns:SOAP-ENV="" <SOAP-ENV:Body> <ns1:getMessage xmlns:ns1="urn:NextMessage" SOAP-ENV:encodingStyle=""> <return xsi:type="xsd:string">Call mom!</return> </ns1:getMessage> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

  20. SOAP Endpoint Reference POST /servlet/rpcrouterHTTP/1.1 Host: Content-Type: text/xml; charset="utf-8" Content-Length: nnnn SOAPAction: "" <SOAP-ENV:Envelope xmlns:SOAP-ENV="" <SOAP-ENV:Body> <ns1:getMessagexmlns:ns1="urn:NextMessage" SOAP-ENV:encodingStyle=""> <UserID xsi:type="xsd:string">JDoe</UserID> <Password xsi:type="xsd:string">0JDOE0</Password> </ns1:getMessage> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 80 /servlet/rpcrouter/getMessage

  21. SOAP client-server interaction

  22. The Apache eXtensible Interaction System (AXIS) • A very flexible SOAP engine from Apache • Open and pluggable architecture • Design to cope with various deployment configuration • From very simplistic to highly sophisticated configurations • The Java Web Services facility (JWS) • Drop-in development • Simplest and quickest way to deploy a Java-base Web Service • Rename source file from to xxx.jws • Drop xxx.jws into JWS directory

  23. APIs de Java • SAAJ (SOAP with Attachment API for Java) tratar mensajes SOAP como objetos Java • JAX-RPC (Java API for XML based RPC) WSDL/XML <-> Java API para cliente: WSDL, Invocación, proxy dinámico • JWSDL acceso a descripciones WSDL • JAXR (Java API for XML registries) acceso a registros de servicios Web ...

  24. Creación de un Servicio Web • Utilizar JWS • Con limitaciones (no package, ...) • WSDD (Web Service Deployment Descriptor)

  25. Creación de un cliente • Acceder a WSDL http: ....Calculator.jws?wsdl -> almacenar Calculator.wsdl • Generar stubs java org.apache.axis.wsdl.WSDL2Java –p Calculator Calculator.wsdl • Clases generadas ls Calculator/ *.java • Compilar javac Calculator/ *.java • Compilar cliente javac • Ejecutar cliente java ClienteCalculator

  26. What is WSDL? • SOAP • specifies the communication between a requesterand aprovider • WSDL • describes the services offered by theprovider (an “endpoint”) • and might be used as a recipe togenerate the proper SOAPmessages to access the services. • WSDL describes network services by using an XML grammar. • A WSDL document has a role similar to an IDL file in CORBAor the Remote Interface in a Java RMI implementation.

  27. Complete picture of distributed applications (using WS)

  28. WSDL service port 1-M binding 1-1 1-M port types operation 1-1 message 1-M types 1-M

  29. Types: xSchema definition of data Service Port Binding <types> <schema targetNamespace="" xmlns=""> <elementname="TradePriceRequest"> <complexType> <elementname="tickerSymbol" type="string"/> </complexType> </element> <element name="TradePrice"> <complexType> <element name="price" type="float"/> </complexType> </element> </schema> </types> Port Types Operations Messages Types

  30. Messages: meaningful collections of Types Service Port Binding Port Types Operations <message name="GetLastTradePriceInput"> <part name="body" element="xsd1:TradePriceRequest"/> </message> <message name="GetLastTradePriceOutput"> <part name="body" element="xsd1:TradePrice"/> </message> Messages Types

  31. Operations: available Methods Service Port Binding Port Types Operations <operation name="GetLastTradePrice"> <soap:operation soapAction=""/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> Messages Types

  32. Port Types: XML in/out for specific methods Maps Operations toMessages Service Port Binding <portType name="StockQuotePortType"> <operation name="GetLastTradePrice"> <input message="tns:GetLastTradePriceInput"/> <output message="tns:GetLastTradePriceOutput"/> </operation> </portType> Port Types Operations Messages Types

  33. Binding: Maps Protocols to Methods (Http, etc.) Service Port <binding name="StockQuoteSoapBinding“ type="tns:StockQuotePortType"> <soap:binding style="document“ transport=""/> <operation name="GetLastTradePrice"> <soap:operation soapAction=""/> <input> <soap:body use="literal"/> </input> <output> <soap:body use="literal"/> </output> </operation> </binding> Binding Port Types Operations Messages Types

  34. Port: Maps URLs to Methods Service <port name="StockQuotePort" binding="tns:StockQuoteBinding"> <soap:address location=""/> </port> Port Binding Port Types Operations Messages Types

  35. Service: Packages ports & bindings Service <service name="StockQuoteService"> <documentation>My first service</documentation> <port name="StockQuotePort" binding="tns:StockQuoteBinding"> <soap:address location=""/> </port> </service> Port Binding Port Types Operations Messages Types

  36. Document structure of WSDL • <definitions>element: the root of any WSDL • The name attributespecifies the name of theWeb Service (usually it corresponds to the file name). • it contains a set of namespacedefinitions that are used throughout the document. • ... • <definitions name ='weatherservice‘ xmlns=''> • …… • </definitions>

  37. Document structure of WSDL • <definitions>contains other elements • elements • types • messages • portType • bindings • services • ... • Each element within the document may contain a<documentation> element to provide some human readableexplanation of the element that is specified. • In addition, all theelements contain an attribute “name” serving as an identifier.

  38. Document structure of WSDL • <types>element • Provide data types definitions • All data type definitions relevant for sending and receiving themessages described • Thespecification suggests using XML schema definitions. <types> <schema targetNamespace="" xmlns=""> <element name="exampleType"> ... </element> ... </schema> </types>

  39. Document structure of WSDL • <message>element • specifiy the data that will be communicated between a requester and a service • may appear multiple times and consists of aname and one or more <part> elements. • The parts specify the contents of the message. <message name='Weather.GetTemperature'> <part name='zipcode' type='xsd:string'/> <part name='celsius' type='xsd:boolean'/> </message> <message name='Weather.GetTemperatureResponse'> <part name='Result' type='xsd:float'/> </message>

  40. Document structure of WSDL • <operation> element • In order to tie the defined messages together as a request-response pair corresponding to a method call. • An operation specifies which message is the input and which message is the output. <operation name='GetTemperature'> <input message='wsdlns:Weather.GetTemperature'/> <output message='wsdlns:Weather.GetTemperatureResponse'/> </operation>

  41. Document structure of WSDL • <portType> element • The collection of all operations (i.e. methods) exposed by your service <portType name='WeatherSoapPort'> <operation name='GetTemperature'> <input message='wsdlns:Weather.GetTemperature'/> <output message='wsdlns:Weather.GetTemperatureResponse'/> </operation> <!-- other operations would go here --> </portType>

  42. Document structure of WSDL • <binding> element • to bind the operation to the SOAP protocol. The elements presented so far described our operation in ageneric way (Nothing has been said about a concreteimplementation). • Next to a name attribute it contains a type attribute that references a portType and provides predefined binding for protocols such as SOAP, HTTP, and MIME. <binding name='WeatherSoapBinding' type='wsdlns:WeatherSoapPort'> …. </binding>

  43. Document structure of WSDL • <binding> element (cont) • Binding to SOAP Inside the <binding> element you have a WSDL SOAP extension element called <soap:binding> which is used to specify the transport protocol you’re using (SOAP can be used over HTTP, SMTP, or possibly any other transport) and the style of request (rpc and document are the two styles). <soap:binding style='rpc' transport=''/>

  44. Document structure of WSDL • <binding> element (cont) • Then for each operation that this service exposes, you specify the value of the SOAPAction that is used for the HTTP header of SOAP message <binding name='WeatherSoapBinding' type='wsdlns:WeatherSoapPort'> <soap:binding style='rpc' transport=''/> <operation name='GetTemperature'> <soap:operation soapAction=''/> .... </operation> </binding>

  45. Document structure of WSDL • <binding> element (cont) • There has to be at least one binding for every portType. • In order to specify how the input and output messages of this operation are encoded, there is an operation element having three subelements: input, output, and fault. Each operation corresponds to an operation in the portType element. <binding name='WeatherSoapBinding' type='wsdlns:WeatherSoapPort'> <soap:binding style='rpc' transport=''/> <operation name='GetTemperature'> <soap:operation soapAction=''/> <input> <soap:body use='encoded' namespace='' encodingStyle=''/> </input> <output> <soap:body use='encoded' namespace='' encodingStyle=''/> </output> </operation> </binding>

  46. Document structure of WSDL • <service> and <port> element • A service is a set of related ports. • The binding is specified within the port element. • In order to bind to the SOAP protocol a <soap:address> is defined. • It contains a name and a location that defines an address of the same type as the transport specified in the soap:binding element. That means that we have to define a HTTP address.  See the Web Service Example

  47. WSDL Structure Overview • portType • Abstract definition of a service (set of operations) • Multiple bindings per portType: • How to access it • Ports • Where to access it Service Port (e.g. http://host/svc) Port Binding (e.g. SOAP) Binding Abstract interface portType operation(s) inMesage outMessage

  48. WSDL Example: float Weather::GetTemperature(String zipCode, bool celsius) { if (celsius) return 21.7; else return 71.06; }

  49. WSDL Example: Defining Services • You can think of the class as the Web service and the GetTemperature method as an operation on that service. To describe this service, you use the WSDL <service> element. <definitions name ='weatherservice‘ xmlns=''> <service name='WeatherService'> …… </service> </definitions>