Web Services Dongwon Lee Ph D IST 516
Web Services Dongwon Lee, Ph. D. IST 516 Fall 2011
Web Services l “Web services are a new breed of Web application. They are self-contained, selfdescribing, modular applications that can be published, located, and invoked across the Web services perform functions, which can be anything from simple requests to complicated business processes. . . Once a Web service is deployed, other applications (and other Web services) can discover and invoke the deployed service…” l Mark Colan, IBM, 2004 l http: //www. ibm. com/developerworks/webservices/library/ws-soaintro. html 2
Web Services l “A software system designed to support interoperable machine-to-machine interaction over a network…” l l W 3 C: http: //www. w 3. org/TR/ws-gloss/ “Web Services allow programs written in different programming languages on different platforms to communicate each other in a standards-based way”, l Roger Wolter, Microsoft, 2001 l http: //msdn. microsoft. com/en-us/library/ms 996507. aspx 3
Web Services Forecast (2007) [ Gartner report] Dollars in Billions $250 $316 billion 200 $271 150 100 0 $45 Web-Services. Enabled Software Products n Estimated that revenue for Webservices-enabled software and professional services will grow from $61 billion (2003) to $316 billion IT Professional Services for Web-Services Projects 4
WS-related Standards and Orgs. 5
WS-related Tech. Life-Cycles [Gartner, 2004] Key: Time to Plateau Visibility Opportunistic SODA Opportunities (12 to 18 months) Advanced Web Services (BPEL, WSS, WS TX) Strategic SODA Opportunities (18 to 36 months) Supportive Technology (Foundational) Packaged Integrating Processes BPM BAM Mobile Middleware ESB Event Mgmt. Agents Technology Trigger Transf. and Routing Adapters JCA XML Rosetta. Net eb. XML Ontology. Based Transformation Peak of Inflated Expectations Basic Web Services (WSDL, SOAP, UDDI) Trough of Disillusionment Time MOM EDI CORBA Integration Broker Suites Programmatic Integ. Servers Bus. Rule Engines As of August 2003 Slope of Enlightenment Plateau of Productivity 6
Hype Cycle for Web and User Interaction Tech. [Gartner, 2010] 7
Two Camps of Web Services SOAP Camp l Standard based l l l More powerful SOA (service-oriented architecture) initially started with SOAP camp No standards Lightweight l Heavyweight l l SOAP, UDDI, WSDL WS-I, WS-Security, … REST Camp l l Faster/easier to develop Architectural style closer to WWW Recently more popular 8
#1. SOAP Based Web Services 9
Common Flow 10
Generic Architecture Web Services on the Web Internet Your Company Web Server Firewall Application Server Middle-tier DB Web Services on the Intranet Internal DB Existing Systems Legacy Systems 11
WS Platform l Web Service is l l l XML plus HTTP plus SOAP plus WSDL plus UDDI plus And lots of other WS standards Eg, WS-I, WS-Security, XAML, XLANG, XKMS, XFS, … 12
WS Platform l Web Service is l l l XML HTTP -- transport SOAP -- remote invocation WSDL -- API UDDI -- directory service 13
SOAP l l The name of the SOAP Camp Web Services got originated from a protocol called SOAP Simple Object Access Protocol A HTTP-based protocol specification that defines a uniform way of passing XMLencoded data Similar to RPC (Remote Procedure Call) in old days 14
UDDI l l Universal Description, Discovery and Integration Service UDDI provides a mechanism for client programs to dynamically find other web services White (address, contact, etc), Yellow (industry categorization), Green (technical details) pages Similar to CORBA trader or DNS service 15
Eg, Xmethods. net 16
WSDL l l Web Services Definition Language V 2. 0, 2007 l l http: //www. w 3. org/TR/wsdl 20 -primer/ WSDL provides a way for service providers to describe the basic format of web service requests over different protocols or encodings WSDL is used to describe what a web service can do, where it resides, and how to invoke it Similar to IDL of CORBA in concept 17
WS Implementation Big Picture Android Linux Windows Find WSDL UDDI C++ Client Publish Java Client Perl Client Python Client Invoke Web Service Implementation SOAP 18
Ex 1. Google Search WS l l l Client wants to write a software program that can connect to the Google, issues some query search, and retrieves answers from it Google built Web Service implementation in their server, and published the information in the UDDI already By looking at its WSDL, one knows what kind of APIs Google provides 19
Google. Search. wsdl http: //api. google. com/Google. Search. wsdl Note: This link no longer works – just use this to understand the 20 concept of traditional approach
Ex 1. Google Search WS l WSDL has APIs like: WSDL l UDDI do. Google. Search(string keyword) Publish l This function returns search results in XML format to the client Google Web Service Implementation SOAP 21
Java Client Example package com. google. soap. search; … Google. Search s = new Google. Search(); s. set. Query. String(“xml database”); Google. Search. Result r = s. do. Google. Search(); System. out. println(r. to. String()); … 22
Ex 1. Google Search WS WSDL Java Client do. Google. Search(“xml database”) UDDI Publish In XML format Google Web Service Implementation SOAP 23
SOAP Request Example <? xml version='1. 0' encoding='UTF-8'? > <SOAP-ENV: Envelope xmlns: SOAP-ENV="http: //schemas. xmlsoap. org/soap/envelope/" xmlns: xsi="http: //www. w 3. org/1999/XMLSchema-instance" xmlns: xsd="http: //www. w 3. org/1999/XMLSchema"> <SOAP-ENV: Body> <ns 1: do. Google. Search xmlns: ns 1="urn: Google. Search" SOAP-ENV: encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/"> <key xsi: type="xsd: string">0000000000000000</key> <q xsi: type="xsd: string">xml database</q> <start xsi: type="xsd: int">0</start> <max. Results xsi: type="xsd: int">10</max. Results> <filter xsi: type="xsd: boolean">true</filter> <restrict xsi: type="xsd: string"></restrict> <safe. Search xsi: type="xsd: boolean">false</safe. Search> <lr xsi: type="xsd: string"></lr> <ie xsi: type="xsd: string">latin 1</ie> <oe xsi: type="xsd: string">latin 1</oe> </ns 1: do. Google. Search> </SOAP-ENV: Body> </SOAP-ENV: Envelope> 24
SOAP Response Example <? xml version='1. 0' encoding='UTF-8'? > <SOAP-ENV: Envelope xmlns: SOAP-ENV="http: //schemas. xmlsoap. org/soap/envelope/" xmlns: xsi="http: //www. w 3. org/1999/XMLSchema-instance" xmlns: xsd="http: //www. w 3. org/1999/XMLSchema"> <SOAP-ENV: Body> <ns 1: do. Google. Search. Response xmlns: ns 1="urn: Google. Search" SOAPENV: encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/"> <return xsi: type="ns 1: Google. Search. Result"> <document. Filtering xsi: type="xsd: boolean">false</document. Filtering> <estimated. Total. Results. Count xsi: type="xsd: int">3</estimated. Total. Results. Count> <directory. Categories xmlns: ns 2="http: //schemas. xmlsoap. org/soap/encoding/" xsi: type="ns 2: Array" ns 2: array. Type="ns 1: Directory. Category[0]"></directory. Categories> <search. Time xsi: type="xsd: double">0. 194871</search. Time> <result. Elements xmlns: ns 3="http: //schemas. xmlsoap. org/soap/encoding/" xsi: type="ns 3: Array" ns 3: array. Type="ns 1: Result. Element[3]"> <item xsi: type="ns 1: Result. Element"> <cached. Size xsi: type="xsd: string">12 k</cached. Size> <host. Name xsi: type="xsd: string"></host. Name> <snippet xsi: type="xsd: string"> < b> . . . < /b> on a simple dialog (via < b> teletype< /b> ) with a user, about a < b> . . . < /b> http: //hci. stanford. edu/< b> winograd< /b> /< b> shrdlu< /b> < br> . It is written in < b> Mac. Lisp< /b> , vintage 1970, and to < b> . . . < /b> </snippet> <directory. Category xsi: type="ns 1: Directory. Category"> <special. Encoding xsi: type="xsd: string"></special. Encoding> <full. Viewable. Name xsi: type="xsd: string"></full. Viewable. Name> </directory. Category> <related. Information. Present xsi: type="xsd: boolean">true</related. Information. Present> <directory. Title xsi: type="xsd: string"></directory. Title> <summary xsi: type="xsd: string"></summary> <URL xsi: type="xsd: string">http: //hci. stanford. edu/cs 147/examples/shrdlu/</URL> <title xsi: type="xsd: string">< b> SHRDLU< /b> </title> </item> 25 …
#2. RESTful Web Services 26
HTTP Request Methods l HTTP can use different request methods (aka “verbs”) to describe an action to be performed on the resource in the server l l Resource could be existing or dynamicallygenerated file HTTP Request line has 3 components: GET /path/to/file/index. html HTTP/1. 0 l Two most commonly used verbs l l GET: to read resources POST: to read, update, delete, create resources 27
HTTP GET vs. POST l l l GET method sends only a URL and headers to the server POST method sends a message body as well GET uses URL-encoded data, appended to URL: l l Eg, http: //foo. bar. com/search? name 1=value 1&name 2=val ue 2$name 3=value 3 POST is used when the client needs to send data to the server as part of the request l Eg, uploading a file or submitting a completed form to CGI script 28
REST as Alternative l REST: REpresentational State Transfer l l REST based Web Services l l An architectural style for large-scale software design by R. Fielding in 2000 Called “RESTful” Underpinnings of World-Wide Web (WWW) l l l Stateless client/server architecture Resources with ID (eg, web site with URL): named resources Global methods (eg, POST/GET) 29
REST as Alternative l REST allows client to access “any” resources using HTTP GET/POST request as long as they publish their ID (such as URI) l l No need to use WSDL or SOAP explicitly Many modern web services interface support (only) RESTful style (SOAP-based) Web Services client cannot access resources unless they publish specific API (eg, WSDL) in UDDI Two different “styles” of web s/w architecture 30
REST as Non-Standard l Unlike SOAP based web services, REST is NOT a web standard (but uses web standards such as XML, HTTP, etc) l l l No W 3 C standard specification No vendor selling s/w for you to write REST Architectural Style 31
Directory for REST Camp l SOAP camp has a directory system—UDDI server l l l UDDI enables machines to search and discover relevant web services and their info Can be automated w/o human involvement REST does not have equivalent directory l l l Only directory system where human users have to navigate Manual approach Eg, Programmable. Web http: //www. programmableweb. com/ 32
Programmable. Web: 3, 990 WS (2011) SOAP style: 661 web services REST style: 2, 814 web services 33
Google’s Approach to WS l Google used to support the traditional SOAP based WS l l l “procedure-call” approach for web services From 2007, Google only supports RESTful approach for web services In particular, Google web services use AJAX framework 34
Web as Client & Server Architecture Request Client (IE, Firefox, Opera) Response 35
Web as Client & Server Architecture Request: http: //pike. psu. edu/hello. htm Connect me to: pike. psu. edu I want file: hello. htm “Explain” Response <html><body> Hello World! </body></html> 36
Dynamic Server l We want a piece of code that really “runs” on the client or server side l l Generate different result under different conditions Two kinds of scripts: l l Client side script: running at client side, i. e. , in your browser. Server side script: running at server side, give you the result in the form of pure HTML Eg, PHP-embedded HTML pages 37
Server Side Script: “Say date” Request: http: //pike. psu. edu/date. php Connect me to: pike. psu. edu I want file: date. php This is PHP code date. php <html><body> <? echo date(“l, F d Y”)? > </body></html> execution “Explain” Response <html><body> Tuesday, October 04 2005 </body></html> PHP output here. 38
Client Side Script: AJAX l AJAX: Asynchronous JAva script and Xml l l Coined around 2005 Framework to build interactive web applications Before: web pages need to be re-loaded each time if users want to see different datasets After: by separating web pages and data items (ie, asynchronous), AJAX improves dynamic user interfaces significantly Typically uses l l l XHTML + CSS Java. Script, Jscript XML + Web Service Concept 39
Google WS APIs http: //code. google. com/more/ 40
Preparation https: //explorer. pass. psu. edu/explorer. cgi Will use the following URL as the directory containing my web service examples: http: //www. personal. psu. edu/dul 13/ws 41
Preparation l You need to have a Google Account l l https: //www. google. com/accounts/ Obtain a KEY to use Google AJAX API l http: //code. google. com/apis/loader/signup. html URL to my prepared folder in the PASS 42
Preparation l l KEY: unique identifier for each request to Google <script src="http: //www. google. com/uds/api? file=uds. js& v=1. 0& key=ABQIAAAAgzmw. IE 9 Rku 8 g. Dp 56 FO 8 M Bx. RVi. FCnk 6 CL 9 JYCTww. Fak. Tbqf. C 3 x. Rnanoh. K D 1 Avi. W_9 Ea. TVUvdh 2 Bmuw" type="text/javascript"></ script> 43
Languages to Support l Google AJAX supports many programming languages l l l l Javascript Python Java Perl PHP Flash … We will use Javascript to explain examples 44
Ex 1: Hello World http: //www. personal. psu. edu/dul 13/ws/hello. html l Copy AJAX example to an HTML file, upload it to PASS and access it 45
Ex 2: Hello World with TAB l Modify code in “hello. html” to see different effects “hello-tab. html” Use online documentation at http: //code. google. com/apis/websearch/docs/ l Eg, Tabbed results // tell the searcher to draw itself in tabbed mode draw. Options. set. Draw. Mode(google. search. Search. Control. DRAW_MODE_TABBED); search. Control. draw(element, draw. Options); 46
Example Javascript + HTML l Download 3 files to your PASS and play with them: http: //www. personal. psu. edu/dul 13/ws/hello. html http: //www. personal. psu. edu/dul 13/ws/hello-tab. html http: //www. personal. psu. edu/dul 13/ws/map. html l Lots of RESTful WS examples from Google: http: //code. google. com/more/ 47
Other Similar Web APIs l l Similar to Google’s AJAX based Search WS Yahoo BOSS (Build your Own Search Service) l http: //developer. yahoo. com/search/boss/ 48
Other Similar Web APIs l Microsoft BING Maps AJAX APIs l l http: //www. microsoft. com/maps/developers/web. aspx Many examples using BING Maps 49
NEW: RESTful Custom Search http: //code. google. com/apis/customsearch/v 1/using_rest. html 50
NEW: RESTful Custom Search l REST approach Can retrieve results for a search by sending an HTTP GET request to its ID: l l https: //www. googleapis. com/customsearch/v 1? pa rameters Eg, GET https: //www. googleapis. com/customsearch/v 1? key=INSE RT-YOURKEY&cx=013036536707430787589: _pqjad 5 hr 1 a&q=flow ers&alt=json HTTP/1. 0 q: query string that users provide 51 alt: data format for response: JSON or ATOM
HW #1 (DUE: Oct. 23 11: 55 PM) l https: //online. ist. psu. edu/ist 516/homeworks/ l Tasks: l l l Individual Homework Using the XMLPad, finish out the half-ready XSLT file (that we provide) to transform XML to HTML Turn-In l XSLT file 52
Reference l SOAP Version 1. 2 Part 0: Primer l l Web Services Description Language (WSDL) Version 1. 2 Part 1: Core Language l l l http: //www. w 3 c. org/TR/wsdl 12/ UDDI Version 3. 0 l l http: //www. w 3 c. org/TR/soap 12 -part 0/ http: //uddi. org/pubs/uddi-v 3. 00 -published-20020719. htm Web Service lecture notes, John Park, SNU IE, 2004 Introduction to Web Services, H. Gunzer, Borland 53
- Slides: 53