Friday, October 29, 2010

Notes on Zend SOAP webservice development

Developing SOAP webservices with the Zend Framework is very easy, but there are some things that aren't explicitly mentioned in the documentation. Hopefully this hints will help you to save time.

WSDL caching

While developing a webservice application do not forget to disable WSDL caching, e.g. in your php.ini configuration file.
soap.wsdl_cache_enabled=0

Set path to SOAP server in WSDL file

When you use a controller for your webservice and desire to have two actions, one for the automatically generated WSDL file and one for the server, use the setUri method of the Zend_Soap_AutoDiscover class to set the URI of the server.
$wsdl->setUri('http://example.localhost/index/soapserver');

Error handling

Error handling with exceptions is easy. I suggest to create your own Exception class first, it can be empty for now:

In your webservice class throw your new exception on invalid input for example.
On SOAP server side, you have to register your Exception class:


On Soap client side embed your request in a try - catch block:

Which for example outputs: 'SOAP ERROR: [Receiver] The product ID does not exist!'

The code

The webservice controller:


The webservice class:


The custom Exception class:

No comments:

Post a Comment