Web Services in Context Evolution Web services is
Web Services in Context
Evolution • Web services is the latest in a series of technologies that solve the same problem – Evolutionary technology – A good step • So, what is the problem being solved?
Building Complex Things
A Relationship A IS_PART_OF B • • Partition can be: - Psychological - Physical A’s goal is set by the environment - B’s goal is set by A - Need to achieve B’s goal to do A
Some Code function task() { in = get_data(); if (!in) return false; out = process_data(in); if (!out) return false; report_data(out); } TASK GET PRO REP
Why Modularize? TASK GET PRO REP
Why Modularize? TASK GET PRO REP Who is this? Project manager
Why Modularize? TASK GET PRO REP Company 1
Why Modularize? TASK GET PRO REP Package
Why Modularize? TASK GET PRO REP Trade secret
Why Modularize? FFF AAA GET XXX BBB GET DDD JJJ GET LLL NNN GET QQQ
Why Modularize? TASK GET Computer A PRO REP Computer B
Many Reasons To Modularize • • • Break down complexity Assign subtasks to different teams Different companies can work together Packages and trade secrets Reuse Different computers
Interfaces TASK GET PRO REP
Interfaces Caller needs to know: • What the module does • What data it requires – Meaning – Type – Rules • What data it produces • Environment – Error reporting – Side effects – Performance
Interfaces Module needs to know: • What to do • Data format to return – Type – Rules • Environment – Error reporting – Side effects
Interfaces r = input(‘Radius? ’); a = circle_area(r); if (a == -1) alert(‘Error’); else alert(‘Area: ‘ + a); function circle_area(r){ if ( r <= 0 ) return -1; return 3. 14159 * r; } Function Compute the area of a circle given its radius. Call circle_area ( r ) Arguments r (circle radius): float Must be > 0. Return -1 if error Float (area) otherwise
How Do Modules Connect? • • • Functions Libraries Objects Interprocess Remote procedure call Web services
Functions Main Compiler Functions Linker Executable
Libraries Same as before, or use compiled functions: Main Compiler Linker Functions Executable
Often Used Together Main Application Functions Compiler Linker Library Functions Executable
Objects $s = new Ship(34. 1, 22. 4); $s->move(45, 3); $s->move(55, 2); print s->location(); class Ship { var $_long = null; var $_lat = null; function Ship($lat, $long) { … } function move(heading, duration) { … } function location() { … }
Compiling Objects Application Objects Main Application Functions Library Objects Compiler Linker Library Functions Executable
Inheritance Residential (residence hall) Faculty (department) Commuter Student (hours, program) Person (name, address) IS_A relationship
Interprocess • Processes on same machine • Piping (shell) ls | grep ethic • Named pipes (C code) mkfifo ("mypipe", S_IFIFO | 0755); //write fp = fopen ("pipe 1", "w+"); fprintf (fp, "hello there!n"); //read fp = fopen ("pipe 1", "r"); fgets (line, sizeof(line), fp);
Interprocess • Message queues • Shared memory • Semaphores
How Do Modules Connect? • • • Functions Libraries Objects Interprocess Remote procedure call Web services
Remote Procedure Calls • Call a function/method running on another computer (or another process) • Caller needs to know the address of the remote machine, the name of the function to call, and its parameters
RPC Problems • Crossing platforms – Binary data representation – Marshalling • Crossing network types – Internet to WAN to LAN • RPC schemes can be language-specific – E. g. , Java’s Remote Method Invocation
Enter Web Services • Mechanism to call a function/method on another computer • Heterogeneous platforms, networks, languages, … • Across organizational boundaries • SOAP is the current leader in protocols – Exchange data in plain text
SOAP Calls Application SOAP Library XML Library TCP/IP Library
XML • A data representation language • Everything is text <book cover=‘paperback’> <title>Hippos Askew</title> <author>Jim Askew</author> <author>Mary Matway</author> </book> • XML documents can be validated against a document type definition (DTD)
A Simple Server <? php //* @author Sean Campbell require_once('nusoap. php'); $server = new soap_server; $server->register('tax. Calc'); $server->service($HTTP_RAW_POST_DATA); exit(); function tax. Calc ($rate, $sub) { if ($rate == '' || $rate <= 0) return new soap_fault('Client', '', Need a positive, non-zero tax rate. ', ''); if ($sub == '' || $sub <= 0) return new soap_fault('Client', '', Need a positive, non-zero subtotal. ', ''); return (($rate / 100) * $sub) + $sub; } ? >
Client <? php // @author Sean Campbell require_once('nusoap. php'); $param = array('rate' => '5', 'sub' => '200' ); $client = new soapclient('http: //www. paintcreek. org/test/soap/tax. Calc. php'); $response = $client->call('tax. Calc', $param); if ($client->fault) { echo "FAULT: <p>Code: {$client->faultcode} "; echo "String: {$client->faultstring}"; } else { echo "$". $response; } Go ? >
WSDL • Web Service Definition Language – WSDL is a document written in XML. The document describes a Web service. It specifies the location of the service and the operations (or methods) the service exposes. http: //www. w 3 schools. com/wsdl_intro. asp
Sample Document <message name="get. Term. Request"> <part name="term" type="xs: string"/> </message> <message name="get. Term. Response"> <part name="value" type="xs: string"/> </message> <port. Type name="glossary. Terms"> <operation name="get. Term"> <input message="get. Term. Request"/> <output message="get. Term. Response"/> </operation> </port. Type>
Web Services … • Make it easier to link systems within your firm, regardless of platform – Create wrappers for legacy systems • Make it easier to exchange data with other organizations – Access product catalog, check order status, …
Amazon. com • Catalog available through Web services <? php include("nusoap. php"); $soapclient = new soapclient("http: //soap. amazon. com/schemas 2/Amazon. Web. Services. wsdl", true); $proxy = $soapclient->get. Proxy(); $params = array( 'browse_node' => 18, 'page' => 1, 'mode' => 'books', 'tag' => 'melonfire-20', 'type' => 'lite', 'devtag' => 'YOUR-TOKEN-HERE'); $result = $proxy->Browse. Node. Search. Request($params); print_r($result); ? >
Amazon. com These API methods can be called from any platform and language: • Browse. Node. Search. Request() - retrieve a list of catalog items attached to a particular node in the Amazon database; • ASINSearch. Request() - retrieve detailed information for a given product code; • Keyword. Search. Request() - perform a keyword search on the Amazon database; • Seller. Search. Request() - perform a search for products listed by thirdparty sellers; • Power. Search. Request() - perform an advanced search on the Amazon database; • Similarity. Search. Request() - perform a search for similar items, given a specific product code; • More…
Conclusion • Web services – a new solution to an old problem • Exchange data between any platform and any system • Use plain text and XML
- Slides: 40