Cyrille - 2010-11-05

Hello,
I like to make code not aware of underlying technologies, so, NuSoap can only catch soap_fault and nusoap_fault. It's not nice to have to throw this kind of error in clean code.
So, I did a little hack in NuSOAP to get it aware of throwing PHP Exception. It's perhaps not the better solution, but while waiting a evolution of NuSOAP, it's work :-)

In nusoap_server::service() method, when it handle a POST i've encapsulted the invoke_method() call into a try/catch and automaticly map the Php Exception to a soap_fault.

        if ($rm == 'POST') {
            $this->debug("In service, invoke the request");
            $this->parse_request($data);
            if (! $this->fault)
            {
                try
                {
                    $this->invoke_method();
                }
                catch( Exception $ex )
                {
                    $this->methodreturn = new soap_fault(
                        $ex->getCode(),
                        'server',
                        $ex->getMessage(),
                            array(
                                $ex->getFile(),
                                $ex->getLine(),
                                $ex->getTrace(),
                            )
                        );
                }
            }
            if (! $this->fault) {
                $this->serialize_return();
            }
            $this->send_response();