Edit report at https://bugs.php.net/bug.php?id=48966&edit=1
ID: 48966 Comment by: mark+php at itafroma dot com Reported by: moographics at gmail dot com Summary: namespace in soap headers not put into nested tags Status: Open Type: Bug Package: SOAP related Operating System: OSX PHP Version: 5.2.10 Block user comment: N Private report: N New Comment: Still occurring in PHP 5.3.17 for me: same reproduce code, same expected result, so actual result. I'm using Amazon's php-soap 5.3.17-1.26.amzn1 package on Linux. Previous Comments: ------------------------------------------------------------------------ [2010-12-18 03:56:33] james dot roger dot ward at gmail dot com I've a similar problem in PHP 5.3.3 on OSX and believe that its root cause is the same, thus the add-on comment to this bug rather than filing a new one. Reproduce code: --------------- <?php $client = new SoapClient ("http://soap.m4u.com.au/?wsdl", array ("trace" => 1, "exceptions" => 1)) ; $auth -> userId = "ABC" ; $auth -> password = "DEF" ; $arg -> authentication = $auth ; try { $response = $client -> checkUser ($arg) ; } catch (SoapFault $e) { echo "\nEXCEPTION:\n".$e; echo "\n\nREQUEST WAS:\n"; echo $client -> __getLastRequest () ; exit ; } ?> The namespace prefix is missing from the XML generated to represent the two scalars in the "authentication" object, "userID" and "password". Here's the actual message content, rejected by the server: <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://xml.m4u.com.au/2009"> <SOAP-ENV:Body> <ns1:checkUser> <ns1:authentication> <userId>ABC</userId> <password>DEF</password> </ns1:authentication> </ns1:checkUser> </SOAP-ENV:Body> </SOAP-ENV:Envelope> Here's the expected content: <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://xml.m4u.com.au/2009"> <SOAP-ENV:Body> <ns1:checkUser> <ns1:authentication> <ns1:userId>ABC</ns1:userId> <ns1:password>DEF</ns1:password> </ns1:authentication> </ns1:checkUser> </SOAP-ENV:Body> </SOAP-ENV:Envelope> ------------------------------------------------------------------------ [2009-07-18 07:40:55] moographics at gmail dot com Description: ------------ This has been reported before #40318 and marked as bogus but it is not bogus - it simply fails to work as expected. When using soap classes the generated xml header does not have the namespace prefix for all the tags. When creating a soap header the soapVar is passed. The xml that is generated has the correct namespace prefix for the outer tag that is generated but the inner tags have no prefix. Bug #40318 suggests that the namespace cannot be guessed for the inner tags. I am suggesting that the namespace for the inner tags surely can be assumed from the outer tags namespace. The suggested workaround did not work for me. My workaround was to roll my own xml. Reproduce code: --------------- class AuthHeader { private $UsernameToken; public function __construct($username,$password) { $this->UsernameToken = new AuthDetails($username,$password); } } class AuthDetails { private $Username; private $Password; public function __construct($username,$password) { $this->Username = $username; $this->Password = $password; } } $auth = new AuthHeader('xxx','xxx'); $security_ns = 'http://namespace'; $authvalues = new SoapVar($auth, SOAP_ENC_OBJECT); $header = new SoapHeader($security_ns, 'Security', $authvalues); Expected result: ---------------- <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP- ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://namespace1.xsd" xmlns:ns2="http://namespace2.xsd"> <SOAP-ENV:Header> <ns2:Security> <ns2:UsernameToken> <ns2:Username>xxx</ns2:Username>' <ns2:Password>xxx</ns2:Password> </ns2:UsernameToken> </ns2:Security> </SOAP-ENV:Header> <SOAP-ENV:Body> <ns1:courseListRequest> <ns1:type>courseList</ns1:type> <ns1:origin>review</ns1:origin> <ns1:action>courseList</ns1:action> <ns1:date>2009-07-18T17:28:40</ns1:date> <ns1:staffId>XXX</ns1:staffId> </ns1:courseListRequest> </SOAP-ENV:Body> </SOAP-ENV:Envelope> Actual result: -------------- <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP- ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://namespace1.xsd" xmlns:ns2="http://namespace2.xsd"> <SOAP-ENV:Header> <ns2:Security> <UsernameToken> <Username>XXX</Username>' <Password>XXX</Password> </UsernameToken> </ns2:Security> </SOAP-ENV:Header> <SOAP-ENV:Body> <ns1:courseListRequest> <ns1:type>courseList</ns1:type> <ns1:origin>review</ns1:origin> <ns1:action>courseList</ns1:action> <ns1:date>2009-07-18T17:28:40</ns1:date> <ns1:staffId>XXX</ns1:staffId> </ns1:courseListRequest> </SOAP-ENV:Body> </SOAP-ENV:Envelope> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=48966&edit=1