3 * $Id: wsdlclient4.php,v 1.6 2005/05/12 21:42:06 snichol Exp $
5 * WSDL client sample, based on soap builders round 2 interop.
10 * Authentication: none
12 require_once('../lib/nusoap.php');
14 * Grab post vars, if present
16 $method = isset($_POST['method']) ? $_POST['method'] : '';
17 $null = isset($_POST['null']) ? $_POST['null'] : '';
18 $empty = isset($_POST['empty']) ? $_POST['empty'] : '';
19 $proxyhost = isset($_POST['proxyhost']) ? $_POST['proxyhost'] : '';
20 $proxyport = isset($_POST['proxyport']) ? $_POST['proxyport'] : '';
21 $proxyusername = isset($_POST['proxyusername']) ? $_POST['proxyusername'] : '';
22 $proxypassword = isset($_POST['proxypassword']) ? $_POST['proxypassword'] : '';
24 * When no method has been specified, give the user a choice
27 echo '<form name="MethodForm" method="POST">';
28 echo '<input type="hidden" name="proxyhost" value="' . $proxyhost .'">';
29 echo '<input type="hidden" name="proxyport" value="' . $proxyport .'">';
30 echo '<input type="hidden" name="proxyusername" value="' . $proxyusername .'">';
31 echo '<input type="hidden" name="proxypassword" value="' . $proxypassword .'">';
32 echo 'Method: <select name="method">';
33 echo '<option>echoString</option>';
34 echo '<option>echoStringArray</option>';
35 echo '<option>echoInteger</option>';
36 echo '<option>echoIntegerArray</option>';
37 echo '<option>echoFloat</option>';
38 echo '<option>echoFloatArray</option>';
39 echo '<option>echoStruct</option>';
40 echo '<option>echoStructArray</option>';
41 echo '<option>echoVoid</option>';
42 echo '<option>echoBoolean</option>';
43 echo '<option>echoBase64</option>';
44 echo '</select><br><br>';
45 echo 'Null parameter? <input type="checkbox" name="null" value="1"><br>';
46 echo 'Empty array? <input type="checkbox" name="empty" value="1"><br><br>';
47 echo '<input type="submit" value=" Execute ">';
52 * Execute the specified method
54 if ($method == 'echoString') {
56 $params = array('inputString' => 'If you cannot echo a string, you probably cannot do much');
58 $params = array('inputString' => null);
60 } elseif ($method == 'echoStringArray') {
63 $params = array('inputStringArray' => array('String 1', 'String 2', 'String Three'));
65 $params = array('inputStringArray' => array());
68 $params = array('inputStringArray' => null);
70 } elseif ($method == 'echoInteger') {
72 $params = array('inputInteger' => 329);
74 $params = array('inputInteger' => null);
76 } elseif ($method == 'echoIntegerArray') {
79 $params = array('inputIntegerArray' => array(451, 43, -392220011, 1, 1, 2, 3, 5, 8, 13, 21));
81 $params = array('inputIntegerArray' => array());
84 $params = array('inputIntegerArray' => null);
86 } elseif ($method == 'echoFloat') {
88 $params = array('inputFloat' => 3.14159265);
90 $params = array('inputFloat' => null);
92 } elseif ($method == 'echoFloatArray') {
95 $params = array('inputFloatArray' => array(1.1, 2.2, 3.3, 1/4, -1/9));
97 $params = array('inputFloatArray' => array());
100 $params = array('inputFloatArray' => null);
102 } elseif ($method == 'echoStruct') {
104 $struct = array('varString' => 'who', 'varInt' => 2, 'varFloat' => 3.14159);
105 $params = array('inputStruct' => $struct);
107 $params = array('inputStruct' => null);
109 } elseif ($method == 'echoStructArray') {
112 $structs[] = array('varString' => 'who', 'varInt' => 2, 'varFloat' => 3.14159);
113 $structs[] = array('varString' => 'when', 'varInt' => 4, 'varFloat' => 99.9876);
114 $params = array('inputStructArray' => $structs);
116 $params = array('inputStructArray' => array());
119 $params = array('inputStructArray' => null);
121 } elseif ($method == 'echoVoid') {
123 } elseif ($method == 'echoBoolean') {
125 $params = array('inputBoolean' => false);
127 $params = array('inputBoolean' => null);
129 } elseif ($method == 'echoBase64') {
131 $params = array('inputBase64' => base64_encode('You must encode the data you send; NuSOAP will automatically decode the data it receives'));
133 $params = array('inputBase64' => null);
136 echo 'Sorry, I do not know about method ' . $method;
139 $client = new soapclient('http://www.scottnichol.com/samples/round2_base_server.php?wsdl&debug=1', true,
140 $proxyhost, $proxyport, $proxyusername, $proxypassword);
141 $err = $client->getError();
143 echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
145 $client->useHTTPPersistentConnection();
146 echo '<h2>Execute ' . $method . '</h2>';
147 $result = $client->call($method, $params);
149 if ($client->fault) {
150 echo '<h2>Fault</h2><pre>';
155 $err = $client->getError();
158 echo '<h2>Error</h2><pre>' . $err . '</pre>';
160 // Display the result
161 echo '<h2>Result</h2><pre>';
162 print_r((!is_bool($result)) ? $result : ($result ? 'true' : 'false'));
164 // And execute again to test persistent connection
165 echo '<h2>Execute ' . $method . ' again to test persistent connection (see debug)</h2>';
166 $client->debug("*** execute again to test persistent connection ***");
167 $result = $client->call($method, $params);
169 $client->debug("*** execute again ... ***");
170 $result = $client->call($method, $params);
173 echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
174 echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
175 echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';