Web Services hussein suleman uct csc 3002 f
Web Services hussein suleman uct csc 3002 f 2007
Definitions p Web n n p Web service n n p = World Wide Web = client-server hypermedia system layered over Internet. = Web-based Service (or service) = service provided through the medium of the Web, beyond hypermedia. Web Service n = machine-to-machine communication based on interoperability standards defined by W 3 C/WSI.
SOA and Web Services p Service Oriented Architectures (SOA) are a methodology in software development where software is cast as a set of services with welldefined external interfaces. n Benefits include: p p p modularity reuse Web Services are a specific set of SOA standards for the description of machine-to-machine communication (especially over the Web): n n n SOAP WSDL UDDI
REST as an alternative p Representational State Transfer is an alternative philosophy to SOA. p REST suggests that a resource should ideally be read with only a GET HTTP request, without the overhead of Web Services! n along with other things …
Use case: Registration Register at UCT requests seat in CS Dept CS confirms acceptance UCT contacts your bank Bank transfers money UCT confirms registration Request classes request seat in each class Confirm classes Confirm seats CS confirms seat in 1015 Maths confirms seat in 1043
Mapping to Core Web Services p SOAP n p WSDL n p Service interface description for BANK, UCT, Dept 1, Dept 2, CS. UDDI n p Transport protocol for message passing. Central registry of all services e. g. , CS’s “did we accept you” service. Web-based services for user interaction!
SOAP p Describes an XML format for messages to be exchanged among actors. n n p One-way information transfer. Stateless. Independent of lower-layer transport. Specifies only syntax, not semantics. Used to be “Simple Object Access Protocol”.
SOAP Example <Envelope> <header> <origin>CS</origin> </header> <body> <request. Seat> <class>CSC 115</class> <student. ID>abc 123</student. ID> </request. Seat> </body> </Envelope>
SOAP Actors and Roles p Producer n p Consumer n p Uses/interprets/understands SOAP message. Intermediary n p Creates SOAP message. Modifies message in transmission path between producer and consumer. Role attributes can specify if message block must be understood by next or final node.
SOAP headers and bodies p Headers may contain control information that may be modified by intermediaries. n n p Can have multiple headers. Headers can be modified, removed and inserted by intermediaries. Body contains application payload. n Only one body per message. Many simple use cases do not “need” headers. p Both are defined using XML Schema, as specified in WSDL. p
WSDL p Web Services Description Language defines interactions among WS nodes in terms of: n n p corresponding message pairs or sequence of messages. message types. protocol binding (HTTP or SOAP). network address of service. Using a WSDL definition, a client can determine how to use a Web Service (syntactically).
UDDI p The Universal Description, Discovery and Integration of Web Services (UDDI) is a central/replicated clearinghouse for Web Services. p UDDI is not machine-readable – needs human intervention to select services. p Alternatives now include P 2 P discovery, automatic indices, etc.
UDDI Example 1/4
UDDI Example 2/4
UDDI Example 3/4
UDDI Example 4/4 (WSDL)
Example: Google Web Search API p Until 2006, Google offered a free Web Service interface. n n Up to 1000 requests per day per user. Defined using WSDL, using HTTP-SOAP. Every user must first request a unique key to track user activity, and provide this key with every request. p Requests can be for search results, cached data or spelling checks. p
Google WSDL 1/2 <xsd: complex. Type name="Google. Search. Result"> <xsd: all> <xsd: element name="document. Filtering" <xsd: element name="search. Comments" <xsd: element name="estimated. Total. Results. Count " <xsd: element name="estimate. Is. Exact" <xsd: element name="result. Elements" <xsd: element name="search. Query" <xsd: element name="start. Index" <xsd: element name="end. Index" <xsd: element name="search. Tips" <xsd: element name="directory. Categories" <xsd: element name="search. Time" </xsd: all> </xsd: complex. Type> type="xsd: boolean"/> type="xsd: string"/> type="xsd: int"/> type="xsd: boolean"/> type="typens: Result. El type=" xsd: string"/> type=" xsd: int"/> type=" xsd: string"/> type="typens: Director type=" xsd: double"/> <xsd: complex. Type name="Result. Element"> <xsd: all> <xsd: element name="summary" type="xsd: string"/> <xsd: element name="URL" type="xsd: string"/> <xsd: element name="snippet" type="xsd: string"/> <xsd: element name="title" type="xsd: string"/> <xsd: element name="cached. Size" type="xsd: string"/> <xsd: element name="related. Information. Present " type="xsd: boolean"/> <xsd: element name="host. Name" type="xsd: string"/> <xsd: element name="directory. Category" type="typens: Directory. Category" <xsd: element name="directory. Title" type="xsd: string"/> </xsd: all> </xsd: complex. Type>
Google WSDL 2/2 <message name="do. Google. Search"> <part name="key" type="xsd: string"/> <part name="q" type="xsd: string"/> <part name="start" type="xsd: int"/> <part name="max. Results" type="xsd: int"/> <part name="filter" type="xsd: boolean"/> <part name="restrict" type="xsd: string"/> <part name="safe. Search" type="xsd: boolean"/> <part name="lr" type="xsd: string"/> <part name="ie" type="xsd: string"/> <part name="oe" type="xsd: string"/> </message> <operation name="do. Google. Search"> <input message="typens: do. Google. Search"/> <output message="typens: do. Google. Search. Response"/> </operation>
Google SOAP Request <SOAP-ENV: Envelope xmlns: SOAPENV="http: //schemas. xmlsoap. org/soap/envelope/" xm lns: 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" SOAPENV: encoding. Style="http: //schemas. xmlsoap. org/soap/encoding/"> <key xsi: type="xsd: string">0000000000000000</key> <q xsi: type="xsd: string">uct computer science</q> <start xsi: type="xsd: int">0</start> <max. Results xsi: type="xsd: int">10</max. Results> <filter xsi: type="xsd: boolean">false</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>
Google SOAP Response 1/2 <SOAP-ENV: Envelope> <SOAP-ENV: Body> <ns 1: do. Google. Search. Response> <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. C ount> <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. Cate gories> <search. Time xsi: type="xsd: double">0. 194871</search. Time> <result. Elements xmlns: ns 3="http: //schemas. xmlsoap. org/soap/encoding/" xs i: 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"> some stuff … </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>
Google SOAP Response 2/2 <related. Information. Present xsi: type="xsd: boolean">true</related. Infor mation. 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/sh rdlu/</URL> <title xsi: type="xsd: string">< b> SHRDLU< /b> </title> </item> </result. Elements> <end. Index xsi: type="xsd: int">3</end. Index> <search. Tips xsi: type="xsd: string"></search. Tips> <search. Comments xsi: type="xsd: string"></search. Comments> <start. Index xsi: type="xsd: int">1</start. Index> <estimate. Is. Exact xsi: type="xsd: boolean">true</estimate. Is. Exact> <search. Query xsi: type="xsd: string">shrdlu winograd maclisp teletype</sea rch. Query> </return> </ns 1: do. Google. Search. Response> </SOAP-ENV: Body> </SOAP-ENV: Envelope>
Using Google API from Perl use SOAP: : Lite; # create soap object my $key=‘ 000000000000000’; my $query="uct computer science"; my $google. Search = SOAP: : Lite -> service("file: . /Google. Search. wsdl") -> proxy ('http: //api. google. com/search/beta 2', proxy => ['http' => 'http: //cache. uct. ac. za: 8080']); # submit to server and get results / retry while request not accepted my $result; my $max_retries = 0; my $retry_count = 0; while (!$results->{result. Elements} && $retry_count <= $max_retries) { eval { $result = $google. Search -> do. Google. Search( $key, $query, 0, 10, "false", "", "latin 1"); }; $retry_count++; } # print out titles and URLs foreach my $aresult (@{$result->{'result. Elements'}}) { print (sprintf ("%sn URL: %sn", $aresult->{'title'}, $aresult>{'URL'})); }
Output from Google via Perl Department of <b>Computer Science</b>, University of Cape Town URL: http: //www. cs. uct. ac. za/ Why study at the Department of <b>Computer Science</b>, University of <b>. . . </b> URL: http: //www. cs. uct. ac. za/newstudents/why. html Prospective Undergrad Students for the Department of <b>Computer</b> <b>. . . </b> URL: http: //www. cs. uct. ac. za/newstudents/staffp. html About Us: Department of <b>Computer Science</b>, University of Cape Town URL: http: //www. cs. uct. ac. za/about. html Postgrad Students of the Department of <b>Computer Science</b> <b>. . . </b> URL: http: //www. cs. uct. ac. za/people/stud-postgrad. html Prospective Undergrad Students for the Department of <b>Computer</b> <b>. . . </b> URL: http: //www. cs. uct. ac. za/people/stud-alumni. html Admin staff of the Department of <b>Computer Science</b>, University of <b>. . . </b> URL: http: //www. cs. uct. ac. za/people/staff-admin. html Department of <b>Computer Science</b> URL: http: //moodle. cs. uct. ac. za/ Using Windows CE. NET 4. 1 in <b>UCT' s Computer Science</b> Department URL: http: //arc. cs. odu. edu: 8080/dp 9/getrecord/oai_dc/techreports. cs. uct. ac. za/oai: techre ports. cs. uct. ac. za: 65 Science. Direct - Theoretical <b>Computer Science</b> : Scheduling UET-<b>UCT</b> <b>. . . </b> URL: http: //dx. doi. org/10. 1016/0304 -3975(96)00035 -7
Beyond Google Web Search p Other Google Web APIs n n n Google Maps Google Earth etc. p Google RSS/Atom feeds for GMail. p MSN and Yahoo Web APIs.
Amazon Electronic Commerce p A full suite of Web Services to interface with Amazon. com n n n Both SOAP and REST (URL-encoded) interfaces Many more interfaces than Google. Why? Fewer restrictions on usage, in production and free for many purposes!
Amazon REST Request p http: //webservices. amazon. com/onca/xml? Servic e=AWSECommerce. Service&AWSAccess. Key. Id=00 00000&Operation=Item. Lookup&Item. Id=06 20056886 p base. URL n p Key to access service n p AWSAccess. Key. Id=000000 Operation to perform n p http: //webservices. amazon. com/onca/xml? Service=AW SECommerce. Service Operation=Item. Lookup Item to display n Item. Id=0620056886
Output from Amazon 1/2 <Item. Lookup. Response> <Operation. Request> <HTTPHeaders> <Header Name="User. Agent" Value="Mozilla/5. 0 (Windows; U; Windows NT 5. 1; en-US; rv: 1. 8. 0. 5) Gecko/20060719 Firefox/1. 5. 0. 5"/> </HTTPHeaders> <Request. Id>0 XJBJRVTVME 4 XENAVPQS</Request. Id> <Arguments> <Argument Name="Service" Value="AWSECommerce. Service"/> <Argument Name="Item. Id" Value="0620056886"/> <Argument Name="AWSAccess. Key. Id" Value="0000000000"/> <Argument Name="Operation" Value="Item. Lookup"/> </Arguments> <Request. Processing. Time>0. 0196020603179932</Request. Processing. Time> </Operation. Request> <Items> <Request> <Is. Valid>True</Is. Valid> <Item. Lookup. Request> <Item. Id>0620056886</Item. Id> </Item. Lookup. Request> </Request>
Output from Amazon 2/2 <Item> <ASIN>0620056886</ASIN> <Detail. Page. URL> http: //www. amazon. com/exec/obidos/redirect? tag=ws%26 link_code=xm 2%26 camp=20 25%26 creative=165953%26 path=http: //www. amazon. com/gp/redirect. html%253 f. A SIN=0620056886%2526 tag=ws%2526 lcode=xm 2%2526 c. ID=2025%2526 ccm. ID=165953%25 26 location=/o/ASIN/0620056886%25253 FSubscription. Id=0000000000 </Detail. Page. URL> <Item. Attributes> <Author>Andrew Verster</Author> <Creator Role="Editor">Zuleikha Mayat</Creator> <Creator Role="Photographer">Dennis Bughwan</Creator> <Creator Role="Illustrator">Nalin Bughwan</Creator> <Manufacturer>Domain Enterprises</Manufacturer> <Product. Group>Book</Product. Group> <Title>Indian Delights</Title> </Item. Attributes> </Items> </Item. Lookup. Response>
- Slides: 29