Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * This code attempts to send a SoapServer instance the same ZendDebugger variables used in the
- * environment where the SoapClient was created. The goal is to have complete client and server
- * debugging in one session.
- *
- * The result is that the SoapServer will sometimes return an empty document body, and will return
- * nothing (not even http headers) at other times.
- *
- * This code must be run with a ZendDebugger session to properly appreciate the error.
- */
- //error_reporting(0);
- ini_set('display_errors', false);
- // ZendServer has a default OB
- while (ob_get_level() > 0) {
- trigger_error('Flushing OB',E_USER_NOTICE);
- ob_end_flush();
- }
- $location = 'http://'.$_SERVER['SERVER_NAME'].':'. $_SERVER['SERVER_PORT'].'/'.$_SERVER['PHP_SELF'];
- trigger_error('Using SOAP Server: '.$location,E_USER_NOTICE);
- class MyBook {
- public $author = 'Me';
- public function getAuthor() {
- trigger_error('Server executing getAuthor',E_USER_NOTICE);
- return array('name'=>$this->author);
- }
- }
- if (!empty($_REQUEST['s'])) {
- trigger_error('Server started',E_USER_NOTICE);
- $server = new SoapServer(null, array('location'=>$_SERVER['PHP_SELF'].'?s=1','uri' => "http://test-uri/"));
- $server->setClass('MyBook');
- $server->handle();
- exit;
- } else {
- $location = $location.'?s=1';
- $s = new SoapClient(null,array(
- 'location'=>$location,
- 'uri'=>'http://test-uri/',
- 'trace'=>true,
- // 'style' => SOAP_DOCUMENT,
- // 'style' => SOAP_RPC,
- // 'use' => SOAP_LITERAL,
- // 'soap_version'=>SOAP_1_2,
- ));
- if (!empty($_COOKIE['ZendDebuggerCookie']) || !empty($_REQUEST['debug_port'])) {
- // Creating a ZendDebugger environment for the Soap Server doesn't work with these REQUEST variables alone (are they even needed?)
- $location .= '&'.html_entity_decode(urldecode(http_build_query($_REQUEST)),ENT_QUOTES, 'UTF-8');
- // Setting this header breaks the SOAP service.
- if (!empty($_COOKIE['ZendDebuggerCookie'])) {
- $s->__setCookie('ZendDebuggerCookie',$_COOKIE['ZendDebuggerCookie']);
- }
- }
- try {
- trigger_error('Client executing getAuthor',E_USER_NOTICE);
- $result = $s->getAuthor();
- echo "<html><body>";
- echo "<h2>Response</h2><pre>".print_r($result,true)."</pre>";
- echo "<h2>Soap Transaction</h2>\n".
- "<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".
- "<h3>Server</h3><pre style='color: purple'>" . $s->__getLastResponseHeaders()."\n" . htmlentities($s->__getLastResponse(),ENT_QUOTES,'UTF-8')."</pre>".
- "</body></html>";
- } catch(SoapFault $e) {
- echo "<html><body><h2>SoapFault</h2>\n".
- "<strong>". $e->getMessage()."</strong>\n<pre>" .$e->getTraceAsString()."</pre></strong>".
- "<h3>Client</h3><pre style='color: green; border-bottom: thin solid gray;'>".$s->__getLastRequestHeaders()."\n".htmlentities($s->__getLastRequest(),ENT_QUOTES,'UTF-8')."</pre>\n".
- "<h3>Server</h3><pre style='color: red'>". $s->__getLastResponseHeaders()."\n".htmlentities($s->__getLastResponse(),ENT_QUOTES,'UTF-8')."</pre>".
- "</body></html>";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement