Web Services 2 Lecture 9 1 Outline • SOAP (messaging) • WSDL (service description) • WS-Interoperability (WS-I) • UDDI (registry) • Some practical aspects 2
Reminder: Web Service Architecture "server" Service provider publish bind (WSDL) (SOAP) Service broker Service requestor find (UDDI) "naming service" "client" 3 Message Exchange Patterns • Request – Simple request without response • Request-Response – Client sends request and server responds on same port – Most common 4
Web Evolution Technology TCP/IP HTML XML Connectivity Presentation Programmability Purpose Applications E-Mail, FTP… Web Pages Web Services Create the Web Browse the Web Program the Outcome Web 5 Basic Web Service Usage Scenario 2 http get (manual) web Web Service service lookup Repository 3 WSDL file (UDDI) 1 register write client WSDL file application (manually) publish web service 4 SOAP request deploy client Web Service application 5 SOAP response Provider 6
Web Service Stack • A set of standards for implementing Web services Publication and Discovery: UDDI extends URI extends HTML Service Description: WSDL extends HTTP Messaging: SOAP Transport: HTTP, SMTP, FTTP, … 7 Web Services Implementation Web Service Provider (endpoint) Requestor HTTP SOAP application (SOAP client) server server server SOAP messages (http transport) • Application Server (web service-enabled) – provides implementation of services and exposes it through WSDL/SOAP – implementation in Java, as EJB, as .NET (C#) etc. • SOAP server – implements the SOAP protocol • HTTP server – standard Web server • SOAP client – implements the SOAP protocol on the client site 8
Example Amazon Web Services • www.amazon.com/gp/aws/landing.html • Very large product database exposed through Web Services • Lots of marketing using a certain technology • Idea: let others figure out how to sell products for us – Associates program enables Web sites to link to Amazon.com and earn referral fees 9 SOAP in simple Words • Originally called “Simple Object Access Protocol” • Defines the way how XML documents (messages) are exchanged between client and server Client Server 10
SOAP • Lightweight messaging framework based on XML • Supports simple messaging and RPC (remote procedure calls) • SOAP consists of – Envelope construct: defines the overall structure of messages – Encoding rules: define the serialization of application data types – SOAP RPC: defines representation of remote procedure calls and responses – Binding framework: binding to protocols such as HTTP, SMTP – Fault handling • SOAP supports advanced message processing: – forwarding intermediaries : route messages based on the semantics of message – active intermediaries : do additional processing before forwarding messages, may modify message 11 Client-Server Interaction Client Server Intermediary 12
SOAP Message • SOAP messages consist of – Envelope: top element of XML message ( required ) – Header: general information on message such as security ( optional ) – Body: data exchanged (required) envelope header • Header – elements are application-specific – may be processed and changed by intermediaries or recipient body • Body – elements are application-specific – processed by recipient only 13 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> 14
Minimal SOAP/HTTP Request • SOAP Header is optional so we skip it here POST /InStock HTTP/1.1 Host: www.example.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: nnn <?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: Body xmlns:m="http://www.example.org/stock"> <m: GetStockPrice > <m:StockName>IBM</m:StockName> </m:GetStockPrice> </soap: Body > </soap: Envelope > 15 http://www.w3schools.com/soap/soap_example.asp Minimal SOAP/HTTP Response HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: nnn <?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: Body xmlns:m="http://www.example.org/stock"> <m: GetStockPriceResponse > <m:Price>34.5</m:Price> </m:GetStockPriceResponse> </soap: Body > </soap: Envelope > 16 http://www.w3schools.com/soap/soap_example.asp
Java Class public class TravelAgency { public int reservation(String date), public int passenger(String name), public int itinery(String departing, String arriving, String departureDate), public int returnFlight(String departing, String arriving, String departureDate) } 17 Example: “Complex” SOAP Message Envelope <?xml version='1.0' ?> <env:Envelope xmlns:env="http://www.w3.org/2002/12/soap-envelope"> <env:Header> <m:reservation xmlns:m=http://travelcompany.example.org/reservation http://www.w3.org/TR/2007/REC-soap12-part0-20070427/ env:role =http://www.w3.org/2002/12/soap-envelope/role/next SOAP attributes env:mustUnderstand ="true"> <m:dateAndTime>2001-11-29T13:20:00.000-05:00</m:dateAndTime> </m:reservation> Header <n:passenger xmlns:n=http://mycompany.example.com/employees env:role =http://www.w3.org/2002/12/soap-envelope/role/next SOAP attributes env:mustUnderstand ="true"> <n:name>Åke Jógvan Øyvind</n:name> </n:passenger> </env:Header> <env:Body> <p:itinerary xmlns:p="http://travelcompany.example.org/reservation/travel"> <p:departure> <p:departing>New York</p:departing> <p:arriving>Los Angeles</p:arriving> <p:departureDate>2001-12-14</p:departureDate> Body </p:departure> <p:returnFlight> <p:departing>Los Angeles</p:departing> <p:arriving>New York</p:arriving> <p:departureDate>2001-12-20</p:departureDate> </p:returnFlight> </p:itinerary> 18 </env:Body> </env:Envelope>
Conversational Message Exchanges in SOAP travel agency customer proposed itinerary alternatives choice 19 SOAP RPC (Request) • Encapsulate RPC into SOAP messages – procedure name and arguments – response (return value) – processing instructions (transactional RPC!) • Example: Request message <?xml version='1.0' ?> <env:Envelope xmlns:env="http://www.w3.org/2002/12/soap-envelope" > transaction information <env:Header> <t:transaction xmlns:t="http://thirdparty.example.org/transaction" env:encodingStyle="http://example.com/encoding" env:mustUnderstand="true" >5</t:transaction> </env:Header> TID method invocation <env:Body> <m:chargeReservationRequest env:encodingStyle="http://www.w3.org/2002/12/soap-encoding" xmlns:m="http://travelcompany.example.org/"> <m:reservation xmlns:m="http://travelcompany.example.org/reservation"> <m:code>FT35ZBQ</m:code> parameter 1 </m:reservation> <o:creditCard xmlns:o="http://mycompany.example.com/financial"> <n:name xmlns:n="http://mycompany.example.com/employees"> Åke Jógvan Øyvind </n:name> <o:number>123456789099999</o:number> <o:expiration>2005-02</o:expiration> parameter 2 </o:creditCard> </m:chargeReservationRequest> 20 </env:Body> </env:Envelope>
SOAP RPC (Response) • Example cntd.: Response message <?xml version='1.0' ?> <env:Envelope xmlns:env="http://www.w3.org/2002/12/soap-envelope" > <env:Header> <t:transaction xmlns:t=http://thirdparty.example.org/transaction env:encodingStyle=http://example.com/encoding env:mustUnderstand="true">5</t:transaction> </env:Header> <env:Body> method result <m:chargeReservationResponse env:encodingStyle=http://www.w3.org/2002/12/soap-encoding xmlns:m="http://travelcompany.example.org/"> <m:code>FT35ZBQ</m:code> <m:viewAt> http://travelcompany.example.org/reservations?code=FT35ZBQ </m:viewAt> output parameters </m:chargeReservationResponse> </env:Body> </env:Envelope> 21 SOAP Processing Model (1) • Elements in the Header may carry SOAP-specific attributes controlling the message processing – attributes from namespace http://www.w3.org/2002/12/soap-envelope – role, mustUnderstand, relay, encodingStyle • " role " attribute – if processing node matches role in header, it must process the header – special role "next": receiving node must be capable of processing header – special role "ultimateReceiver: receiving node must be capable of processing body • " mustUnderstand " attribute – processing of header information is mandatory 22
Recommend
More recommend