Neil Schreiber - 2011-08-05

I'm having a problem where my php soap webservice is double encoding strings. For example if I try to return the string O'Test, what I get is O'Test. What I would have expected to see is O'Test. It seems like what is happening is the & itself is getting encoded?

I've look through what phpinfo() returns, but I don't see anything obvious.

My code to initialize the soap server uses arrays to automate the initialization of my functions and types but this is the gist of what I'm doing:

$server = new soap_server();
$server->configureWSDL('server', 'urn:sg');
$server->wsdl->addComplexType( 'testCall', 'complexType', 'struct', 'all', '', array( 'name' => 'testName', 'type' => 'xsd:string' ) );
$server->register( $fname,
array( 'request' => 'tns:TestCallRequest' ),
array( 'return' => 'tns:TestCallResponse' ),
'urn:sg#testCall' );

Here is the function represented by $fname above:

function testCall() {
    $result = array();
    $result[testName] = 'O\'Test';
    return $result;

Here is the soap request and response that I see from a client perspective:

<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soapenv="" xmlns:urn="urn:sg"><soapenv:Header/><soapenv:Body><urn:testCall soapenv:encodingStyle=""><urn:TestCallRequest></urn:TestCallRequest></urn:testCall></soapenv:Body></soapenv:Envelope>

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="" xmlns:SOAP-ENV="" xmlns:xsd="" xmlns:xsi="" xmlns:SOAP-ENC="" xmlns:tns="urn:sg"><SOAP-ENV:Body><ns1:TestCallResponse xmlns:ns1="urn:sg"><return xsi:type="tns:TestCallResponse"><testName xsi:type="xsd:string">O&amp;apos;Test</testName></return></ns1:TestCallResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

I'm starting to read through nusoap.php to see if I can figure out why this is happening. I could fix it on my client (my client is an iphone) by double decoding everything that I receive, but that is inefficient and shouldn't be necessary, should it?