1

I created a webservice that returns an array in response, my webservice is build with Zend in my controller I do this:

$soap = new Zend_Soap_Server("http://blabla/wsdl");
$soap->setClass('Foo');
$soap->handle();
exit;

This is the Foo class with the function I call:

class Foo {
    /**
     * Test general
     * @param Int $param
     * @return Array
     */
    public function general($param) {
        return array('a' => 'b');
    }
}

I call it with:

$options = array(
    "trace" => 1,
    "exceptions" => 0,
    "cache_wsdl" => 0
);
$soap = new SoapClient('http://blabla/wsdl', $options);
print_r('<pre>');print_r($soap->general(6));
exit;

But, I don't want it to return an array, but a xml... How could I do that?

salathe
  • 51,324
  • 12
  • 104
  • 132
PHPScriptor
  • 11
  • 1
  • 2

2 Answers2

4

To retrieve the last response XML as a string, call SoapClient::__getLastResponse().

$response = $soap->general(6);
$response_xml = $soap->__getLastResponse();

This requires that the trace option is turned on, which you are already doing.

salathe
  • 51,324
  • 12
  • 104
  • 132
-1

Here's a similar Q: How to convert array to SimpleXML

class Foo {
    /**
     * Test general
     * @param Int $param
     * @return Array
     */
    public function general($param) {
        //return array('a' => 'b');
        $xml = new SimpleXMLElement('<root/>');
        $a = array('a' => 'b');
        array_walk($a, array($xml,'addChild'));
        return $xml->asXML();

    }
}
Community
  • 1
  • 1
Charlie
  • 1,062
  • 6
  • 9