PHP overriding “Soapaction” header

Oh no, SOAP again. I hate SOAP…. but making shit work is everyone’s job. So, here i go again. This time i need (don’t ask why) to change the Soapaction header. It turns out to be quite simple with the bundled Soap extension of PHP. Just need to extend the SoapClient and override the  __doRequest function. The code:

<?

class CustomSoapClient extends SoapClient {
  function __doRequest($request, $location, $action, $version, $one_way = 0) {
    $action = 'my_custom_soap_action'; // override soapaction here
    return parent::__doRequest($request, $location, $action, 
                               $version, $one_way);
  }
}


$options = array('exceptions'=>true,
                 'trace'=>1,
                 'cache_wsdl'=>WSDL_CACHE_NONE
                 );
            
$client = new CustomSoapClient('my.wsdl', $options);

try {
  $input = new stdClass();
  $input->property  = "example";
  $input->property2 = "example2";
   
  $response = $client->helloWorld($input);   
   
} catch (Exception $e) {
  echo "\n";
  echo 'Caught exception: ',  $e->getMessage(), "\n";
  echo "\n";
  echo "REQUEST:\n" . $client->__getLastRequestHeaders() .
                      $client->__getLastRequest() . "\n";
  echo "\n";
  echo "RESPONSE:\n" . $client->__getLastResponseHeaders() . 
                       $client->__getLastResponse() . "\n";   
}			
			
?>