3 * Library of SOAP functions wrapping the PHP5 SOAP functions
5 * The purpose of this wrapping is to make it easier to use alternative SOAP
6 * implementations like nuSOAP in case the PHP5 SOAP extension is not available
8 * @author Alex Smith and others members of the Serving Mathematics project
9 * {@link http://maths.york.ac.uk/serving_maths}
10 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
15 * Create a new SoapClient object
17 * @param string $wsdl URI of the WSDL file
18 * @param boolean $trace indicates if the soap messages should be saved (i.e. if
19 * get_soap_messages is used) and should be used only for debugging
20 * @return mixed Returns either a SoapClient object or, if the connection failed,
23 function soap_connect($wsdl, $trace=false) {
25 $connection = new SoapClient($wsdl, array('soap_version'=>SOAP_1_1
, 'exceptions'=>true, 'trace'=>$trace));
27 catch (SoapFault
$f) {
30 catch (Exception
$e) {
31 $connection = new SoapFault('client', 'Could not connect to the service');
37 * Make a call to a SoapClient
39 * @param SoapClient $connection The SoapClient to call
40 * @param string $call Operation to be performed by client
41 * @param array $params Parameters for the call
42 * @return mixed The return parameters of the operation or a SoapFault
43 * If the operation returned several parameters then these
44 * are returned as an object rather than an array
46 function soap_call($connection, $call, $params) {
48 $return = $connection->__soapCall($call, $params);
50 catch (SoapFault
$f) {
53 catch (Exception
$e) {
54 $return = new SoapFault('client', 'Could call the method');
56 // return multiple parameters using an object rather than an array
57 if (is_array($return)) {
58 $keys = array_keys($return);
60 foreach ($keys as $key) {
61 if (!is_string($key)) {
67 $return = (object) $return;
72 function soap_serve($wsdl, $functions) {
73 // create server object
74 $s = new SoapServer($wsdl);
76 foreach ($functions as $func)
77 $s->addFunction($func);
82 function make_soap_fault($faultcode, $faultstring, $faultactor='', $detail='', $faultname='', $headerfault='') {
83 return new SoapFault($faultcode, $faultstring, $faultactor, $detail, $faultname, $headerfault);
86 function get_last_soap_messages($connection) {
87 return array('request'=>$connection->__getLastRequest(), 'response'=>$connection->__getLastResponse());
90 // Fix simple type encoding - work around a bug in early versions of PHP5 < 5.0.3, see http://bugs.php.net/bug.php?id=31832
91 function soap_encode($value, $name, $type, $namespace, $encode=XSD_STRING
) {
92 $value = new SoapVar($value, $encode, $type, $namespace);
95 return new SoapParam($value, $name);
98 // Fix complex type encoding - work around a bug in early versions of PHP5 < 5.0.3, see http://bugs.php.net/bug.php?id=31832
99 function soap_encode_object($value, $name, $type, $namespace) {
100 if (!is_object($value))
102 $value = new SoapVar($value, SOAP_ENC_OBJECT
, $type, $namespace);
105 return new SoapParam($value, $name);
108 // Fix array encoding - work around a bug in early versions of PHP5 < 5.0.3, see http://bugs.php.net/bug.php?id=31832
109 function soap_encode_array($value, $name, $type, $namespace) {
110 if (!is_array($value))
112 $value = new SoapVar($value, SOAP_ENC_ARRAY
, 'ArrayOf' . $type, $namespace);
115 return new SoapParam($value, $name);