- Timestamp:
- 2011/10/25 00:02:55 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_11-dev/data/module/SOAP/example/client.php
r20119 r21299 16 16 * @package SOAP 17 17 * @author Shane Caraveo <[email protected]> Port to PEAR and more 18 * @copyright 2003-2005 The PHP Group 18 * @author Jan Schneider <[email protected]> Maintenance 19 * @copyright 2003-2007 The PHP Group 19 20 * @license http://www.php.net/license/2_02.txt PHP License 2.02 20 21 * @link http://pear.php.net/package/SOAP 21 22 */ 22 23 24 /** SOAP_Client */ 23 25 require 'SOAP/Client.php'; 24 26 25 /** 26 * This client runs against the example server in SOAP/example/server.php. It 27 /* This client runs against the example server in SOAP/example/server.php. It 27 28 * does not use WSDL to run these requests, but that can be changed easily by 28 * simply adding '?wsdl' to the end of the url. 29 */ 29 * simply adding '?wsdl' to the end of the url. */ 30 30 $soapclient = new SOAP_Client('http://localhost/SOAP/example/server.php'); 31 // This namespace is the same as declared in server.php.32 $options = array('namespace' => 'urn:SOAP_Example_Server',33 'trace' => true);34 31 32 /* Set a few options. */ 33 $options = array(); 34 35 /* This namespace is the same as declared in server.php. */ 36 $options['namespace'] = 'urn:SOAP_Example_Server'; 37 38 /* Trace the communication for debugging purposes, so we can later inspect the 39 * data with getWire(). */ 40 $options['trace'] = true; 41 42 /* Uncomment the following lines if you want to use Basic HTTP 43 * Authentication. */ 44 // $options['user'] = 'username'; 45 // $options['pass'] = 'password'; 46 47 header('Content-Type: text/plain'); 48 49 /* Calling echoStringSimple. */ 35 50 $ret = $soapclient->call('echoStringSimple', 36 $params =array('inputStringSimple' => 'this is a test string'),51 array('inputStringSimple' => 'this is a test string'), 37 52 $options); 38 // print$soapclient->getWire();53 // echo $soapclient->getWire(); 39 54 print_r($ret); 40 echo " <br>\n";55 echo "\n"; 41 56 57 /* Calling echoString. */ 42 58 $ret = $soapclient->call('echoString', 43 $params =array('inputString' => 'this is a test string'),59 array('inputString' => 'this is a test string'), 44 60 $options); 61 // echo $soapclient->getWire(); 45 62 print_r($ret); 46 echo " <br>\n";63 echo "\n"; 47 64 65 /* Calling divide with valid parameters. */ 48 66 $ret = $soapclient->call('divide', 49 $params =array('dividend' => 22, 'divisor' => 7),67 array('dividend' => 22, 'divisor' => 7), 50 68 $options); 51 // print$soapclient->getWire();69 // echo $soapclient->getWire(); 52 70 if (PEAR::isError($ret)) { 53 echo 'Error: ' . $ret->getMessage() . "<br>\n";71 echo 'Error: ' . $ret->getMessage(); 54 72 } else { 55 echo 'Quotient is ' . $ret . "<br>\n";73 echo 'Quotient is ' . $ret; 56 74 } 75 echo "\n"; 57 76 77 /* Calling divide with invalid parameters. */ 58 78 $ret = $soapclient->call('divide', 59 $params =array('dividend' => 22, 'divisor' => 0),79 array('dividend' => 22, 'divisor' => 0), 60 80 $options); 81 // echo $soapclient->getWire(); 61 82 if (PEAR::isError($ret)) { 62 echo 'Error: ' . $ret->getMessage() . "<br>\n";83 echo 'Error: ' . $ret->getMessage(); 63 84 } else { 64 echo 'Quotient is ' . $ret . "<br>\n";85 echo 'Quotient is ' . $ret; 65 86 } 87 echo "\n"; 66 88 67 68 // SOAPStruct is defined in the following file. 89 /* The SOAPStruct class is defined in example_types.php. */ 69 90 require_once 'example_types.php'; 70 71 91 $struct = new SOAPStruct('test string', 123, 123.123); 72 92 … … 74 94 * we provide if possible. */ 75 95 $soapclient->_auto_translation = true; 96 76 97 /* You can explicitly set the translation for a specific 77 98 * class. auto_translation works for all cases, but opens ANY class in the … … 80 101 $soapclient->setTypeTranslation('{http://soapinterop.org/xsd}SOAPStruct', 81 102 'SOAPStruct'); 103 104 /* Calling echoStruct. */ 82 105 $ret = $soapclient->call('echoStruct', 83 $p =array('inputStruct' => $struct->__to_soap()),106 array('inputStruct' => $struct->__to_soap()), 84 107 $options); 85 // print$soapclient->getWire();108 // echo $soapclient->getWire(); 86 109 print_r($ret); 87 110 88 /* *89 * PHP doesn't support multiple OUT parameters in function calls, so we must90 * do a little work to make it happen here. This requires knowledge on the91 * developers part to figure out how they want to deal with it.92 * /111 /* Calling echoStructAsSimpleTypes. 112 * PHP doesn't support multiple return values in function calls, so we must do 113 * a little work to make it happen here, for example returning an array 114 * instead. This requires knowledge on the developers part to figure out how 115 * they want to deal with it. */ 93 116 $ret = $soapclient->call('echoStructAsSimpleTypes', 94 $p =array('inputStruct' => $struct->__to_soap()),117 array('inputStruct' => $struct->__to_soap()), 95 118 $options); 119 // echo $soapclient->getWire(); 96 120 if (PEAR::isError($ret)) { 97 echo 'Error: ' . $ret->getMessage() . "<br>\n";121 echo 'Error: ' . $ret->getMessage(); 98 122 } else { 99 123 list($string, $int, $float) = array_values($ret); 100 echo "varString: $string <br>\nvarInt: $int<br>\nvarFloat: $float<br>\n";124 echo "varString: $string\nvarInt: $int\nvarFloat: $float"; 101 125 } 126 echo "\n"; 127 128 /* Calling echoMimeAttachment. 129 * We want to use MIME encoding here, the default is to use DIME encoding. */ 130 $options['attachments'] = 'Mime'; 131 $attachment = new SOAP_Attachment('attachment', 'text/plain', null, 132 'This is a MIME attachment'); 133 $ret = $soapclient->call('echoMimeAttachment', 134 array($attachment), 135 $options); 136 // echo $soapclient->getWire(); 137 print_r($ret);
Note: See TracChangeset
for help on using the changeset viewer.
