root/docs/usc/nautilus/usr2/prod/buoys/perl/xml/nusoap/samples/wsdlclient12.php

Revision 113 (checked in by jcothran, 5 years ago)

example php/perl script to process nerrs cdmo web service data to Xenia database.

Line 
1 <?php
2 /*
3  *    $Id: wsdlclient12.php,v 1.3 2005/01/24 21:58:48 snichol Exp $
4  *
5  *    WSDL client sample.
6  *
7  *    Service: WSDL
8  *    Payload: document/literal
9  *    Transport: http
10  *    Authentication: none
11  */
12 require_once('../lib/nusoap.php');
13 require_once('../lib/class.wsdlcache.php');
14 $proxyhost = isset($_POST['proxyhost']) ? $_POST['proxyhost'] : '';
15 $proxyport = isset($_POST['proxyport']) ? $_POST['proxyport'] : '';
16 $proxyusername = isset($_POST['proxyusername']) ? $_POST['proxyusername'] : '';
17 $proxypassword = isset($_POST['proxypassword']) ? $_POST['proxypassword'] : '';
18
19 $method = isset($_GET['method']) ? $_GET['method'] : 'ItemSearch';
20
21 echo 'You must set your own Amazon E-Commerce Services subscription id in the source code to run this client!'; exit();
22 $SubscriptionId = 'Your AWS subscription id';
23
24 $wsdlurl = 'http://webservices.amazon.com/AWSECommerceService/US/AWSECommerceService.wsdl';
25 $cache = new wsdlcache('.', 120);
26 $wsdl = $cache->get($wsdlurl);
27 if (is_null($wsdl)) {
28     $wsdl = new wsdl($wsdlurl,
29                     $proxyhost, $proxyport, $proxyusername, $proxypassword);
30     $cache->put($wsdl);
31 } else {
32     $wsdl->debug_str = '';
33     $wsdl->debug('Retrieved from cache');
34 }
35 $client = new soapclient($wsdl, true,
36                         $proxyhost, $proxyport, $proxyusername, $proxypassword);
37 $err = $client->getError();
38 if ($err) {
39     echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
40 }
41
42 $client->soap_defencoding = 'UTF-8';
43
44 function GetCartCreateParams() {
45     global $SubscriptionId;
46
47     // create items to be added to the cart
48     $item = array ();
49     $item[0] = array(  "ASIN" => "0596004206",
50                        "Quantity" => "1"
51                     );
52     $item[1] = array(  "ASIN" => "0596003277",
53                        "Quantity" => "2"
54                     );
55
56     // pack it to <Item> array
57     $items =  array("Item" => $item);
58     // Construct request parameters
59     $request = array("Items" => $items, "ResponseGroup" => "CartSimilarities");
60     
61     // Construct  all parameters
62     $cartCreate = array(    "SubscriptionId"  => $SubscriptionId,
63                             "Request" => $request
64                          );
65
66     return $cartCreate;
67 }
68
69 function GetItemSearchParams() {
70     global $SubscriptionId;
71
72     $itemSearchRequest = array(
73         'BrowseNode' => '53',
74         'ItemPage' => 1,
75     //    'ResponseGroup' => array('Request', 'Small'),
76         'SearchIndex' => 'Books',
77         'Sort' => 'salesrank'
78     );
79     
80     $itemSearch = array(
81         'SubscriptionId' => $SubscriptionId,
82     //    'AssociateTag' => '',
83     //    'Validate' => '',
84     //    'XMLEscaping' => '',
85     //    'Shared' => $itemSearchRequest,
86         'Request' => array($itemSearchRequest)
87     );
88     
89     return $itemSearch;
90 }
91
92 function GetItemSearchParams2() {
93     global $SubscriptionId;
94
95     $request = array(
96         "Keywords" => "postal stamps",
97         "SearchIndex" => "Books"
98     );
99
100     $itemSearch = array(
101         'SubscriptionId' => $SubscriptionId,
102         'Request' => $request
103     );
104
105     return $itemSearch;
106 }
107
108 if ($method == 'ItemSearch') {
109     $result = $client->call('ItemSearch', array('body' => GetItemSearchParams()));
110 } elseif ($method == 'ItemSearch2') {
111     $result = $client->call('ItemSearch', array('body' => GetItemSearchParams2()));
112 } elseif ($method == 'CartCreate') {
113     $result = $client->call('CartCreate', array('body' => GetCartCreateParams()));
114 } else {
115     echo "Unsupported method $method";
116     exit;
117 }
118
119 // Check for a fault
120 if ($client->fault) {
121     echo '<h2>Fault</h2><pre>';
122     print_r($result);
123     echo '</pre>';
124 } else {
125     // Check for errors
126     $err = $client->getError();
127     if ($err) {
128         // Display the error
129         echo '<h2>Error</h2><pre>' . $err . '</pre>';
130     } else {
131         // Display the result
132         echo '<h2>Result</h2><pre>';
133         print_r($result);
134         echo '</pre>';
135     }
136 }
137 echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
138 echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
139 echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
140 ?>
141
Note: See TracBrowser for help on using the browser.