How to generate a wsdl using zend soap

Gary Paluk picture Gary Paluk · Jan 13, 2011 · Viewed 8k times · Source

I'm trying to generate a wsdl file using the autodiscover class from the Zend framework. The resulting definition doesn't seem to become available and subsequent functionality doesn't work.

Below is the code that I'm using...

<?php

/**
 * Returns Hello World as a string.
 *
 * @return string
 */
 function hello( )
 {
  return "Hello World";
 }


 if( isset( $_GET['wsdl'] ) )
 {
  $autodiscover = new Zend_Soap_AutoDiscover();
  $autodiscover->addFunction( 'hello' );
  $autodiscover->handle();
 }
 else if( isset( $_GET['client'] ) )
 {
  $client = new Zend_Soap_Client( "http://localhost/service.php" );
  echo $client->hello();
 }
 else
 {
  $server = new Zend_Soap_Server( "http://localhost/service.php?wsdl" );
  $server->addFunction( 'hello' );
  $server->handle();
 }

?>

This all weems to fail silently, calling http://localhost/service.php?wsdl just dies silently and generates no WSDL definition. Could someone please give me an idea of what I'm doing wrong :)

Many thanks

Answer

Johnny Everson picture Johnny Everson · Jan 27, 2011

I tried the code you posted, except that I added: require('Zend/Soap/AutoDiscover.php');. It worked.