I decide to try my hand at creating a soap server using the Zend Framework. This was an exersice in getting me more familiar with ZF and web services. Hopefully this will help others. I think the code is pretty self explanitory but feel free to ask questions or provide comments.
Basically the WSDL is auto generated by php if the URL ends in ?wsdl, if not then the soap server is created and the request handled.
/*
* Check to see if soap call is to be handled
* or if the WSDL should be displayed
*/
if(isset($_GET['wsdl']))
{
createWSDL();
}
else
{
/*
* Soap Server WSDL document
*/
$wsdl = 'http://' . $_SERVER["SERVER_NAME"] .
$_SERVER['PHP_SELF'] . '?wsdl';
/*
* Create a new soap server
*/
$server = new Zend_Soap_Server($wsdl,
array('soap_version' => SOAP_1_2)
);
/*
* Set the server to cache the wsdl file
*/
$server->setWsdlCache(1);
/*
* Set the class for the web service
*/
$server->setClass('Cisc_Ws_Cs3webservice');
/*
* Set soap server persistance (For use with login feature)
*/
$server->setPersistence(SOAP_PERSISTENCE_SESSION);
/*
* Register exceptions
*/
$server->registerFaultException('Exception');
/*
* Handle the soap call
*/
$server->handle();
}
/**
* Create the WSDL file for display
*
* @param none
* @return string The wsdl xml
*/
function createWSDL()
{
$wsdl = new Zend_Soap_AutoDiscover();
$wsdl->setClass('Cisc_Ws_Cs3webservice');
$wsdl->handle();
}
The WSDL is created from the class file, so make sure you use proper documentation blocks for you code. The only issue I have seen so far is that if a function input in the class is a integer,
no matter what is inputted, an integer will be pass to the function. This makes it difficult to verify data, say that your getting an integer and not a float. The workaround is to pass an array
and check the values of the array.