Hi guys,
I have problem with reaching data from SOAP non wsdl mode. I’m using SoapClient library, but maybe you can give me some other approach because I’m getting error “Procedure ‘getProduct’ not present” ".
Although the documentation says that the procedure should work.
Here is my code:
class SpectorCLASS {
const VERSION = '1.0.0';
const SOAP_VERSION = SOAP_1_1; // don't change
const SOAP_TRACE = 1;
const SOAP_EXCEPTIONS = 0;
var $WS;
function __construct($service) {
if (!extension_loaded('soap'))
die('PHP SOAP extension not loaded! Please install it');
switch ($service) {
case 'Inventory':
$url = 'https://www.spectorapps.com/pws_product/Inventory/Inventory.php'; //production
break;
case 'ProductData':
$url = 'https://www.spectorapps.com/pws_product/product/index.php'; //production';
$uri = 'https://www.spectorapps.com/pws_product/product/'; //production';
break;
case 'MediaContent':
$url = 'https://www.spectorapps.com/pws_product/productmedia/productMediaService.php'; //production';
break;
case 'PriceConfig':
$url = 'https://www.spectorapps.com/pws_product/PPC/ppcService.php'; //production
break;
}
$sctx = stream_context_create(
array(
'http' => array(
'header' =>
"Content-type: application/soap+xml; charset=utf-8\r\nUser-Agent: ORION-SOAP\r\n"
)
)
);
$this->WS = new SoapClient(
null,
array(
'location' => $url,
'uri' => $uri,
'trace' => 1
)
);
}
function debug($soapFault) {
var_dump($soapFault);
echo "Request :<pre>", htmlentities($this->WS->__getLastRequest()), "</pre>";
echo "Request Headers:<pre>", htmlentities($this->WS->__getLastRequestHeaders()), "</pre>";
echo "Response :<pre>", htmlentities($this->WS->__getLastResponse()), "</pre>";
echo "Response Headers:<pre>", htmlentities($this->WS->__getLastResponseHeaders()), "</pre>";
}
}
//function
define('SPECTOR_USER', '190888');
define('SPECTOR_PASS', '*********');
function getProductData($pid){
$client2 = new SpectorCLASS('ProductData');
$ProductDataWS = $client2->WS;
try {
set_time_limit(0);
ini_set ( 'max_execution_time' , 0);
$ProductData = $ProductDataWS->getProduct(
array(
'wsVersion'=>'1.0.0',
'id'=>SPECTOR_USER,
'password'=>SPECTOR_PASS,
'localizationCountry' => 'US',
'localizationLanguage' => 'en',
'productId'=>"$pid"
)
);
if($ProductData===null) return array();
$out = object_to_array($ProductData);
return $out;
}
catch (SoapFault $soapFault) {
return $client2->debug($soapFault);
}
}
/*-----------------------------------------------------------------------------------------------*/
//function call
$p_data = getProductData ( 'ST4143' );
$p_data = $p_data ['Product'];
echo '<pre>';
var_dump ( $p_data );