function echoStruct($inputStruct) { if (is_object($inputStruct) && strtolower(get_class($inputStruct)) == 'soapstruct') { return $inputStruct->__to_soap('return'); } else { if (is_object($inputStruct)) { $inputStruct = get_object_vars($inputStruct); } $struct = new SOAPStruct($inputStruct['varString'], $inputStruct['varInt'], $inputStruct['varFloat']); return $struct->__to_soap('return'); } }
function echoStruct($inputStruct) { $ns = '{http://soapinterop.org/xsd}'; if (is_object($inputStruct) && strtolower(get_class($inputStruct)) == 'soapstruct') { return $inputStruct->__to_soap($ns . 'return'); } else { if (is_object($inputStruct)) { $inputStruct = get_object_vars($inputStruct); } $struct = new SOAPStruct($inputStruct['varString'], $inputStruct['varInt'], $inputStruct['varFloat']); return $struct->__to_soap($ns . 'return'); } }
$string_array_null_soapval->arrayType = '{http://www.w3.org/2001/XMLSchema}string'; $integer = 12345; $integer_soapval = new SOAP_Value('inputInteger', 'int', $integer); $integer_array = array(1, 234324324, 2); $integer_array_soapval = new SOAP_Value('inputIntegerArray', 'Array', array(new SOAP_Value('item', 'int', 1), new SOAP_Value('item', 'int', 234324324), new SOAP_Value('item', 'int', 2))); $integer_array_null = null; $integer_array_null_soapval = new SOAP_Value('inputIntegerArray', 'Array', null); $integer_array_null_soapval->arrayType = '{http://www.w3.org/2001/XMLSchema}int'; $float = 123.45; $float_soapval = new SOAP_Value('inputFloat', 'float', $float); $float_array = array(1.0, 2343.24324, -2.5); $float_array_soapval = new SOAP_Value('inputFloatArray', 'Array', array(new SOAP_Value('item', 'float', 1.0), new SOAP_Value('item', 'float', 2343.24324), new SOAP_Value('item', 'float', -2.5))); $float_array_null = null; $float_array_null_soapval = new SOAP_Value('inputFloatArray', 'Array', null); $float_array_null_soapval->arrayType = '{http://www.w3.org/2001/XMLSchema}float'; $soapstruct = new SOAPStruct('arg', 34, 325.325); $soapstruct_soapval = $soapstruct->__to_soap(); $soapstruct_header_soapval = $soapstruct->__to_soap('{http://soapinterop.org/echoheader/}echoMeStructRequest'); $soapstruct_array = array($soapstruct, $soapstruct, $soapstruct); $soapstruct_array_soapval = new SOAP_Value('inputStructArray', 'Array', array($soapstruct_soapval, $soapstruct_soapval, $soapstruct_soapval)); $soapstructstruct = new SOAPStructStruct('arg', 34, 325.325, $soapstruct); $soapstructstruct_soapval = $soapstructstruct->__to_soap(); $soapstructstruct_array = array($soapstructstruct, $soapstructstruct, $soapstructstruct); $soapstructstruct_array_soapval = new SOAP_Value('inputStructArray', 'Array', array($soapstructstruct_soapval, $soapstructstruct_soapval, $soapstructstruct_soapval)); $soaparraystruct = new SOAPArrayStruct('arg', 34, 325.325, array('good', 'bad', 'ugly')); $soaparraystruct_soapval = $soaparraystruct->__to_soap(); $soaparraystruct_array = array($soaparraystruct, $soaparraystruct, $soaparraystruct); $soaparraystruct_array_soapval = new SOAP_Value('inputStructArray', 'Array', array($soaparraystruct_soapval, $soaparraystruct_soapval, $soaparraystruct_soapval)); $simpletypes = array('inputString' => 'arg', 'inputInteger' => 34, 'inputFloat' => 325.325); $simpletypes_soapval = array(); $simpletypes_soapval[] = new SOAP_Value('inputString', 'string', 'arg');
$ret = $soapclient->divide(22, 7); // echo $soapclient->getWire(); if (is_a($ret, 'PEAR_Error')) { echo 'Error: ' . $ret->getMessage() . "\n"; } else { echo 'Quotient is ' . $ret . "\n"; } $ret = $soapclient->divide(22, 0); if (is_a($ret, 'PEAR_Error')) { echo 'Error: ' . $ret->getMessage() . "\n"; } else { echo 'Quotient is ' . $ret . "\n"; } /* SOAPStruct is defined in the following file. */ require_once './example_types.php'; $struct = new SOAPStruct('test string', 123, 123.123); /* Tell the client to translate to classes we provide if possible. * You can explicitly set the translation for a specific class. * auto_translation works for all cases, but opens ANY class in the script to * be used as a data type, and may not be desireable. Both can be used on * client or server. */ $soapclient->_auto_translation = true; $soapclient->setTypeTranslation('{http://soapinterop.org/xsd}SOAPStruct', 'SOAPStruct'); $ret = $soapclient->echoStruct($struct->__to_soap()); // echo $soapclient->getWire(); print_r($ret); /* PHP doesn't support multiple OUT parameters in function calls, so we must * do a little work to make it happen here. This requires knowledge on the * developers part to figure out how they want to deal with it. */ $ret = $soapclient->echoStructAsSimpleTypes($struct->__to_soap()); if (is_a($ret, 'PEAR_Error')) {
} else { echo 'Quotient is ' . $ret; } echo "\n"; /* Calling divide with invalid parameters. */ $ret = $soapclient->call('divide', array('dividend' => 22, 'divisor' => 0), $options); // echo $soapclient->getWire(); if (PEAR::isError($ret)) { echo 'Error: ' . $ret->getMessage(); } else { echo 'Quotient is ' . $ret; } echo "\n"; /* The SOAPStruct class is defined in example_types.php. */ require_once 'example_types.php'; $struct = new SOAPStruct('test string', 123, 123.123); /* Send an object, get an object back. Tell the client to translate to classes * we provide if possible. */ $soapclient->_auto_translation = true; /* You can explicitly set the translation for a specific * class. auto_translation works for all cases, but opens ANY class in the * script to be used as a data type, and may not be desireable. Both can be * used on client or server. */ $soapclient->setTypeTranslation('{http://soapinterop.org/xsd}SOAPStruct', 'SOAPStruct'); /* Calling echoStruct. */ $ret = $soapclient->call('echoStruct', array('inputStruct' => $struct->__to_soap()), $options); // echo $soapclient->getWire(); print_r($ret); /* Calling echoStructAsSimpleTypes. * PHP doesn't support multiple return values in function calls, so we must do * a little work to make it happen here, for example returning an array