Guest User

Marques Johansson

a guest
Mar 13th, 2009
182
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /**
  3.  * This code attempts to send a SoapServer instance the same ZendDebugger variables used in the
  4.  * environment where the SoapClient was created.  The goal is to have complete client and server
  5.  * debugging in one session.
  6.  *
  7.  * The result is that the SoapServer will sometimes return an empty document body, and will return
  8.  * nothing (not even http headers) at other times.
  9.  *
  10.  * This code must be run with a ZendDebugger session to properly appreciate the error.
  11.  */
  12. //error_reporting(0);
  13. ini_set('display_errors', false);
  14.  
  15. // ZendServer has a default OB
  16. while (ob_get_level() > 0) {
  17.     trigger_error('Flushing OB',E_USER_NOTICE);
  18.     ob_end_flush();
  19. }
  20.  
  21. $location = 'http://'.$_SERVER['SERVER_NAME'].':'. $_SERVER['SERVER_PORT'].'/'.$_SERVER['PHP_SELF'];
  22.  
  23. trigger_error('Using SOAP Server: '.$location,E_USER_NOTICE);
  24.  
  25. class MyBook {
  26.     public $author = 'Me';
  27.     public function getAuthor() {
  28.         trigger_error('Server executing getAuthor',E_USER_NOTICE);
  29.         return array('name'=>$this->author);
  30.     }
  31. }
  32.  
  33. if (!empty($_REQUEST['s'])) {
  34.     trigger_error('Server started',E_USER_NOTICE);
  35.  
  36.     $server = new SoapServer(null, array('location'=>$_SERVER['PHP_SELF'].'?s=1','uri' => "http://test-uri/"));
  37.     $server->setClass('MyBook');
  38.  
  39.     $server->handle();
  40.     exit;
  41. } else {
  42.     $location = $location.'?s=1';
  43.  
  44.     $s = new SoapClient(null,array(
  45.         'location'=>$location,
  46.         'uri'=>'http://test-uri/',
  47.         'trace'=>true,
  48.         // 'style' => SOAP_DOCUMENT,
  49.         // 'style' => SOAP_RPC,
  50.         // 'use' => SOAP_LITERAL,
  51.         // 'soap_version'=>SOAP_1_2,
  52.     ));
  53.  
  54.     if (!empty($_COOKIE['ZendDebuggerCookie']) || !empty($_REQUEST['debug_port'])) {
  55.         // Creating a ZendDebugger environment for the Soap Server doesn't work with these REQUEST variables alone (are they even needed?)
  56.         $location .= '&'.html_entity_decode(urldecode(http_build_query($_REQUEST)),ENT_QUOTES, 'UTF-8');
  57.         // Setting this header breaks the SOAP service.
  58.         if (!empty($_COOKIE['ZendDebuggerCookie'])) {
  59.             $s->__setCookie('ZendDebuggerCookie',$_COOKIE['ZendDebuggerCookie']);
  60.         }
  61.     }
  62.  
  63.     try {
  64.         trigger_error('Client executing getAuthor',E_USER_NOTICE);
  65.         $result = $s->getAuthor();
  66.  
  67.         echo "<html><body>";
  68.         echo "<h2>Response</h2><pre>".print_r($result,true)."</pre>";
  69.         echo "<h2>Soap Transaction</h2>\n".
  70.             "<h3>Client</h3><pre style='color: green; border: 0px 0px 0px 1px solid gray;'>" . $s->__getLastRequestHeaders()."\n" . htmlentities($s->__getLastRequest(),ENT_QUOTES,'UTF-8')."</pre>\n".
  71.             "<h3>Server</h3><pre style='color: purple'>" . $s->__getLastResponseHeaders()."\n" . htmlentities($s->__getLastResponse(),ENT_QUOTES,'UTF-8')."</pre>".
  72.             "</body></html>";
  73.     } catch(SoapFault $e) {
  74.         echo "<html><body><h2>SoapFault</h2>\n".
  75.             "<strong>".    $e->getMessage()."</strong>\n<pre>" .$e->getTraceAsString()."</pre></strong>".
  76.             "<h3>Client</h3><pre style='color: green;  border-bottom: thin solid gray;'>".$s->__getLastRequestHeaders()."\n".htmlentities($s->__getLastRequest(),ENT_QUOTES,'UTF-8')."</pre>\n".
  77.             "<h3>Server</h3><pre style='color: red'>". $s->__getLastResponseHeaders()."\n".htmlentities($s->__getLastResponse(),ENT_QUOTES,'UTF-8')."</pre>".
  78.             "</body></html>";
  79.     }
  80. }
RAW Paste Data