Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making SOAP Clients more fault tolerant when using class mapping

Tags:

php

soap

wsdl

I'm writing a PHP wrapper for a SOAP service and using the class map option so I can work with objects instead of arrays. This works great until the provider of the SOAP service decides to add a new property to one of their objects (which they seem to like doing without telling anyone) at which point the SOAP client breaks with the error SOAP-ERROR: Encoding: object has no 'NewlyAddedProperty' property as there's now a property in the wsdl that isn't in the class.

I've tried to work around it by using a magic getter and returning things like false, null etc but as they're not valid values according to the wsdl it still throws up a fatal error.

In an ideal world the client would just set that new property on the object even if there isn't a property defined on the class, is that possible? If not just suppressing the error would also be fine.

like image 565
pogo Avatar asked Oct 13 '15 15:10

pogo


1 Answers

You can remove SoapClient's class mapping and use another one, eg jsonmapper.

If your classes are annotated correctly, it's as simple as this example:

class noBisnodePersonClient extends SoapClient {

    // ...

    /**
     * sokPerson
     * @param noBisnodePersonSok $PersonSokReq
     * @return noBisnodePersonSokResponse
     */
    public function sokPerson(noBisnodePersonSok $PersonSokReq){
        $return = $this->__soapCall(
            'sokPerson',
            array($PersonSokReq),
            array('uri'=>'http://dbonline.no/webservices/wsdl/PersonInfo')
        );
        $mapper = new JsonMapper();
        $object = $mapper->map($return, new noBisnodePersonSokResponse);
        return $object;
    }
}
like image 121
Marek Avatar answered Nov 09 '22 22:11

Marek