PHP soap server double encoding html strings

Help
2011-08-05
2013-06-06
  • Neil Schreiber
    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',
    'urn:sg#testCall' );
    $server->service($HTTP_RAW_POST_DATA);
    

    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="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:sg"><soapenv:Header/><soapenv:Body><urn:testCall soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><urn:TestCallRequest></urn:TestCallRequest></urn:testCall></soapenv:Body></soapenv:Envelope>

    <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 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?