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