I'm preparing the SOAP server and generating my WSDL using the follow code:
//(... Controller action code ...)
if (key_exists('wsdl', $params)) {
$autodiscover = new AutoDiscover();
$autodiscover->setClass('WebServiceClass')
->setUri('http://server/webserver/uri');
$autodiscover->handle();
} else {
$server = new Server(null);
$server->setUri($ws_url);
$server->setObject($this->getServiceLocator()->get('MyControllerServiceWebServiceClass'));
$server->handle();
}
//(... Controller action code ...)
But in one of my WebService method I have a parameter of type Array in which each element is of type "MyOtherClass", like follows:
/**
* Add list of MyOtherClass items
*
* @param MyOtherClass[] $items
*
* @return bool
*/
function add($items) {
// Function code here
}
When I try to generate the WSDL I get the follow error:
PHP Warning: DOMDocument::loadXML(): Empty string supplied as input in /<zend framweork path>/Server/vendor/zendframework/zendframework/library/Zend/Soap/Server.php on line 734
Or this Exception:
Cannot add a complex type MyOtherClass[] that is not an object or where class could not be found in "DefaultComplexType" strategy.
When I added to my code something like this:
//(...)
if (key_exists('wsdl', $params)) {
$autodiscover = new AutoDiscover();
$autodiscover->setClass('WebServiceClass');
$autodiscover->setUri($ws_url);
$complex_type_strategy = new ZendSoapWsdlComplexTypeStrategyArrayOfTypeComplex();
$complex_type_strategy->addComplexType('MyOtherClass');
$autodiscover->setComplexTypeStrategy($complex_type_strategy);
$autodiscover->handle();
} else {
//(...)
I get the follow error message:
Fatal error: Call to a member function getTypes() on a non-object in /<project dir>/vendor/zendframework/zendframework/library/Zend/Soap/Wsdl/ComplexTypeStrategy/AbstractComplexTypeStrategy.php on line 54
In resume, the question is: how can I make aware the WSDL of the new Custom Type used as parameter?
Thanks
I did something similar and this is a sample code:
This is a fragment of the function signature of one of the classes that the autodiscover will generate the wsdl based on the annotations:
This is the class ViewModelsPatientViewModel and ViewModelDiagnosisViewModel Notice here how i used the annotations to declare that a field conatins an array of a complextype, and then how that is translated as ArrayOfDiagnosisViewModel on the wsdl
And this is the WSDL generated
NOTICE THAT JUST BY CHANGING THE STRATEGY AND THE RIGHT DOCBLOCKS ANNOTATIONS YOU CAN ACHIEVE THAT.
HOPE THIS SNIPPETS CAN HELP YOU TO FIND A SOLUTION.