Advertisement
jamesggordon

Simple Zend_Soap Example

Jun 27th, 2012
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. <?php
  2. set_include_path( '../zf1/library/' . get_include_path());
  3. require_once "Zend/Loader/Autoloader.php";
  4. Zend_Loader_Autoloader::getInstance();
  5.  
  6. if ( isset( $_GET['wsdl']))
  7. {
  8.     $auto = new Zend_Soap_AutoDiscover();
  9.     $auto->setClass('Foo');
  10.     $auto->handle();
  11. }
  12. else if ( empty( $HTTP_RAW_POST_DATA ))
  13. {
  14.     $client = new Zend_Soap_Client('http://localhost/zstest.php?wsdl' );
  15.  
  16.     try
  17.     {
  18.         echo 'Elements: ', $client->ping( array( 'blah' => null )), '<br />';
  19.     }
  20.     catch ( Exception $e )
  21.     {
  22.         echo 'Exception caught: ', $e->faultcode , ' - ', $e->faultstring, '<br />';
  23.     }
  24.  
  25.     echo '<h2>Request</h2><br /><pre>', htmlentities( $client->getLastRequest()), '</pre>';
  26.     echo '<h2>Response</h2><br /><pre>', htmlentities( $client->getLastResponse()), '</pre>';
  27. }
  28. else
  29. {
  30.     $server = new Zend_Soap_Server( 'http://localhost/zstest.php?wsdl' );
  31.     $server->setClass( 'Foo' );
  32.     $server->handle();
  33. }
  34.  
  35. class Foo
  36. {
  37.     /** @return int */
  38.     public function ping( $testData = null )
  39.     {
  40.         return count( $testData );
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement