__doRequest() to change some content before call

From: Date: Thu, 31 Aug 2006 07:32:57 +0000
Subject: __doRequest() to change some content before call
Groups: php.soap 
Request: Send a blank email to php-soap+get-2366@lists.php.net to get a copy of this message
Hi list, i've got interop problem with a server, and i've read that i can modify soap request content if i subclass soapClient and overload __doRequest Method, i tried this, but i can't manage to get it working... i've added a log method to see if my request is ok before calling the parent method, and it is, but any modification done in this step seems to be non operant after parent::__doRequest call and therefor in not shown in $client->__getLastRequest(); Here is the code i use, if somebody can tell my why, thanks in advance. Cheers Xavier ------------------------------------------------------------------ <?php class MySoapClient extends SoapClient { function __construct($wdsl, $params) {
       parent::__construct($wdsl, $params);
} function __doRequest($request, $location, $action, $version) { $request = str_replace('ns2', 'soapHeader', $request); $this->_log($request); return parent::__doRequest($request, $location, $action, $version); } function _log($req) {
     ob_start();
     print_r($req);
     $out = date('H:i:s') . "  _ _ _ _ _ _ _ _ _ _ _ _ _ _ \n";
     $out .= ob_get_clean() . "\n\n";
        $fh = fopen('test.txt', 'a');
     fwrite($fh, $out);
     fclose($fh);
} } $client = new MySoapClient("mywsdl.wsdl",array(
"trace"      => 1,
"exceptions" => 0, 'location'=> 'http://localhost/soapserver/server.php' )); $ns = 'soapHeader'; $clientName = 'Boobi'; $userName = 'xav'; $password = 'Boo'; $dataAuth = array( 'ClientName' => new SoapVar($clientName, XSD_STRING, null, null, null, $ns), 'UserName' => new SoapVar($userName, XSD_STRING, null, null, null, $ns), 'Password' => new SoapVar($password, XSD_STRING, null, null, null, $ns), ); $hBody = new SoapVar($dataAuth, SOAP_ENC_OBJECT); $header= new SoapHeader($ns, 'AuthenticationHeader', $hBody); $client->__setSoapHeaders(array($header)); $client->getContractors(); //$client->getContractors(); print "<xmp>\n"; print "Request :\n". $client->__getLastRequest() ."\n"; print "Response:\n". $client->__getLastResponse()."\n"; print "</xmp>"; ?> ------------------------------------------- here is the request return by my log method before parent::__doRequest, for my needs it's ok <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.data.com/inventorymsgs/v1" xmlns:soapHeader="soapHeader"><SOAP-ENV:Header> <soapHeader:AuthenticationHeader> <soapHeader:ClientName>Boobi</soapHeader:ClientName> <soapHeader:UserName>xav</soapHeader:UserName> <soapHeader:Password>Boo</soapHeader:Password> </soapHeader:AuthenticationHeader></SOAP-ENV:Header> <SOAP-ENV:Body><ns1:GetContractorsRequest/></SOAP-ENV:Body></SOAP-ENV:Envelope> ----------------------- Here is what __getLastRequest() returns , it's the same request as before calling my custom __doRequest --------------------------- <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.data.com/inventorymsgs/v1" xmlns:ns2="soapHeader"> <SOAP-ENV:Header> <ns2:AuthenticationHeader> <ns2:ClientName>Boobi</ns2:ClientName> <ns2:UserName>xav</ns2:UserName> <ns2:Password>Boo</ns2:Password> </ns2:AuthenticationHeader> </SOAP-ENV:Header> <SOAP-ENV:Body><ns1:GetContractorsRequest/></SOAP-ENV:Body></SOAP-ENV:Envelope>

« previous php.soap (#2366) next »