views:

330

answers:

1

I am trying to use a function from SOAP, which will fetch details about a specific news item. The problem is that I don't get the expected results, just a a strange error. I am using the built-in SOAP client in PHP5.

My error is:

Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: External reference 'https://newsclient.omxgroup.com/cdsPublic/viewDisclosure.action?disclosureId=379485&messageId=454590' in /home/**/public_html/**/updatenews3.php:15

My code is:

<?php
    $login = '***';
    $password = '***';   
    $client = new SoapClient(
    'https://newsclient.omxgroup.com/wsdl/DisclosureNewsService.wsdl',
    array(
        'login' => $login,
        'password' => $password
    ));
    $param = array('lastPublicationId' => 361825);
    $result = $client->fetchNews($param);
?>

The error is the same for all lastPublicationId, where a result is found. It seems as if PHP is trying to load a link, which is found somewhere in the XML-reply (the URL, which is in the error message), and can't access it. Even though I have googled this a lot, I can't find any solution. The only thing I can find is that this seems to have been reported as a bug in a previous version of PHP, but the error refers to PHP 5.2.2 Since I'm using PHP 5.2.9, I'm thinking it can't be that. I'm suspecting the &-character to be the cause of this error?

The WSDL-file can be found here: https://newsclient.omxgroup.com/wsdl/DisclosureNewsService.wsdl

Does somebody know this error, and know of any solution?

+1  A: 

It's possible that the XML being returned by $client->fetchNews($param); isn't being escaped properly - there seems to be an unescaped & in the URL which is shown in the error message.

Best thing is probably to check exactly what XML is being returned, by turning on tracing and printing the last response:

$client = new SoapClient(
'https://newsclient.omxgroup.com/wsdl/DisclosureNewsService.wsdl',
array(
    'login' => $login,
    'password' => $password,
    'trace' => 1
));
$param = array('lastPublicationId' => 361825);

try {
    $result = $client->fetchNews($param);
}
catch (SoapFault $sf) {
    print '<pre>';
    // print the exception
    print_r($sf);

    // print the XML response
    print $client->__getLastResponse();
}

A workaround (if the server is returning invalid XML) is to use code similar to the above to catch the exception. You can then manually get at the XML returned (using __getLastResponse()), and clean it up yourself (e.g. using htmlenties or a regexp), before returning it and using it in the rest of your application.

Dave Challis