I'm just trying to create my first SOAP/WSDL-based Web Service in PHP. I decided to use PEAR's Services_Webservice package. That's what I coded for purpose of performing some tests (file ws.php):
Code: Select all
<?php
ini_set("include_path", '/home/maciek/php:' . ini_get("include_path") );
ini_set("soap.wsdl_cache_enabled", "0");
require_once 'Services/Webservice.php';
class Box
{
/**
* @var int
*/
public $length = 1;
/**
* @var int
*/
public $width = 2;
/**
* @var int
*/
public $height = 3;
}
class NamedBox extends Box
{
/**
* @var string
*/
public $name = "ABC";
}
$Boxes[1] = new Box();
$Boxes[2] = new Box();
class ws extends Services_Webservice
{
/**
* Some data
*/
private $someData = array (
'A' => array('B', 'C'),
'X' => array('Y', 'Z')
);
/**
* Getting some data
* @param string
* @return string[]
*/
public function getsomeData($key)
{
$result = array();
if (isset($this->someData[$key]))
{
$result = $this->someData[$key];
}
return $result;
}
/**
* Getting Boxes
* @return Box[]
*/
public function getBoxes()
{
return $Boxes;
}
/**
* Getting NamedBox
* @return NamedBox
*/
public function getNamedBox()
{
return new NamedBox();
}
}
$options = array('uri' => 'ws', 'encoding' => SOAP_ENCODED);
$service = new ws('ws', 'description', $options);
$service->handle();
?>1)
Warning: strpos() [function.strpos]: Offset not contained in string in /home/maciek/php/Services/Webservice.php on line 518
2)
Fatal error: Uncaught exception 'ReflectionException' with message 'Class does not exist' in /home/maciek/php/Services/Webservice.php:542 Stack trace: #0 /home/maciek/php/Services/Webservice.php(542): ReflectionClass->__construct('') #1 /home/maciek/php/Services/Webservice.php(420): Services_Webservice->classMethodsIntoStruct() #2 /home/maciek/php/Services/Webservice.php(212): Services_Webservice->intoStruct() #3 /home/maciek/public_html/noticeboard/boxes/ws.php(82): Services_Webservice->handle() #4 {main} thrown in /home/maciek/php/Services/Webservice.php on line 542
Trying to find what is the purpose of the 2nd problem I noticed, that in PEAR's code (Webservice.php file) an empty string is putted to ReflectionClass' constructor (but not in first service call!).
I really do not know why does it happens. I tried to put some echo instructions to print helpful messages but I didn't find a solution. The most strange thing is that over a few hours after first successful call my service starts working again - and again for only one call. Moreover, on localhost I do not have a problem... Could you help me?
Helpful data:
Apache 2.2.17
PHP 5.2.12
PEAR Services_Webservice 0.5.1 (code below)
Code: Select all
for ($i = 0; $i < count($params); ++$i) {
$_class = $params[$i]->getClass();
$_type = ($_class) ? $_class->getName() : $param[1][$i];
$_cleanType = str_replace('[]', '', $_type, $_length);
$_typens = str_repeat('ArrayOf', $_length);
$this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['name'] =
$params[$i]->getName();
$this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['wsdltype'] =
$_typens . $_cleanType;
$this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['type'] =
$_cleanType;
$this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['length'] =
$_length;
$this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['array'] =
($_length > 0 && in_array($_cleanType, $this->simpleTypes))
? true : false;
$this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['class'] =
(!in_array($_cleanType, $this->simpleTypes) && new ReflectionClass($_cleanType))
? true : false; //THAT WAS 542 line
$this->wsdlStruct[$this->classname]['method'][$method->getName()]['var'][$i]['param'] = true;
}Code: Select all
$docComments_Description = trim(substr($_docComments_Description, strpos($_docComments_Description, '*') + 1, strpos($_docComments_Description, '*', 1) - 1));--
Thank you in advance
Maciek