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?

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

-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();

    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.