Auto-Generating a SOAP WSDL using the Zend Framework

WSDL’s are not fun to make by hand. If you have to make a change or add a function, the slowest part would be adding it to the WSDL. Luckily the Zend Framework has allowed us to speed things up a bit by auto-generating the WSDL based on a class that is passed.

$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setClass('YourClassName','', null,$_SERVER['PHP_SELF']);
$autodiscover->handle();

Now if you go to where you have this file located, let’s say:

http://www.testing.com/my_generated_wsdl.php

You can then take a look at it!

Now, normally you will want to wrap this together with the server itself. To do so you would need to add a few more lines of code.

if (isset($_GET['wsdl'])) {

    $autodiscover = new Zend_Soap_AutoDiscover();
    $autodiscover->setClass('YourClassName','', null,$_SERVER['PHP_SELF']);
    $autodiscover->handle();
    
} else {
   
    $wsdl = 'http://www.testing.com/my_generated_wsdl.php';
    $server = new SoapServer($wsdl);
    $server->setClass('YourClassName');
    $server->handle();
    
}

Your Client will look like this:

$wsdl = 'http://www.testing.com/my_generated_wsdl.php';
$client = new SoapClient($wsdl);

The next post will also include the settings needed to authenticate via soap headers on the client/server ends.

Tuesday, December 29th, 2009 API Services, Zend Framework

Leave a Reply

You must be logged in to post a comment.

[ad code=1 align=center]