php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48966 namespace in soap headers not put into nested tags
Submitted: 2009-07-18 07:40 UTC Modified: 2009-07-20 09:39 UTC
Votes:33
Avg. Score:4.7 ± 0.6
Reproduced:31 of 32 (96.9%)
Same Version:5 (16.1%)
Same OS:6 (19.4%)
From: moographics at gmail dot com Assigned:
Status: Open Package: SOAP related
PHP Version: 5.2.10 OS: OSX
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-07-18 07:40 UTC] 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>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-18 03:56 UTC] 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>
 [2012-10-30 15:32 UTC] mark+php at itafroma dot com
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.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Nov 12 16:01:30 2019 UTC