Hi Adam, Thanks for your reply. The namespace parameter works fine. (Classical case of rtfm I guess...) I keep having trouble embedding the <UsernameToken> tags. Calling SoapHeader 'recursively' doesn't do the job. Playing around a bit with classes/arrays gets me close but not quite there: class UPCombo { private $Username; private $Password; public function __construct($NewUsername, $NewPassword) { $this->Username = $NewUsername; $this->Password = $NewPassword; } } //(But just using the UPCombo class doesn't do it, // for the UsernameToken tags to appear we need this:) class UPToken { private $UsernameToken; public function __construct($NewUPCombo) { $this->UsernameToken = $NewUPCombo; } } $kaeUsername = new SoapVar(TMT_API_USERNAME, XSD_STRING, null, null, 'Username', WSSE_URL); $kaePassword = new SoapVar(TMT_API_PASSWORD, XSD_STRING, null, null, 'Password', WSSE_URL); $kaeUPCombo = new UPCombo($kaeUsername, $kaePassword); $kaeUsernameToken = new UPToken($kaeUPCombo); $kaeHdr = new SoapVar($kaeUsernameToken, SOAP_ENC_OBJECT, null, null, 'UsernameToken', WSSE_URL); $kaeSoapHeader_NameSpace = WSSE_URL; $kaeSoapHeader_Name = "Security"; $kaeSoapHeader_Data = $kaeHdr; $kaeSoapHeader_MustUnderstand = true; $kaeSoapHeader = new SoapHeader($kaeSoapHeader_NameSpace, $kaeSoapHeader_Name, $kaeSoapHeader_Data, $kaeSoapHeader_MustUnderstand); This adds the UsernameToken tags BUT for some strange reason, although I specify the namespace, it does not add it to the tags. (So it still doesn't work...) What am I missing here?! Thanks for any input, Peter. (PS! When I use array('ns2:UsernameToken' => $kaeUPCombo) instead of the UPToken class in the SoapVar call it works but I don't want to add the namespace hardcoded for obvious reasons.) (PS2, just bought your php cookbook, very useful!) --- Adam Maccabee Trachtenberg <adam@trachtenberg.com> wrote: > On Thu, 13 Apr 2006, Peter De Vries wrote: > > > I need to create a SOAP header that looks like this: > > > > <ns:Security> > > <ns:UsernameToken> > > <ns:Username>MYUSERNAME</ns:Username> > > <ns:Password>MYPASSWORD</ns:Password> > > </ns:UsernameToken> > > </ns:Security> > > (ns: is the Oasis WS-Security namespace, > > http://schemas.xmlsoap.org/ws/2003/06/secext.) > > > > Looks pretty straightforward, turned out to be harder than I thought... > > I tried 2 approaches: PHP::SOAP (5.0.4 on Fedora Core 4) and > > PEAR::SOAP (0.9.3) > > > > 1. PHP::SOAP > > //WSDL_URL is my WSDL file > > //WSSE_URL is http://schemas.xmlsoap.org/ws/2003/06/secext > > $kaeSoapClient_WsdlUrl = WSDL_URL; > > $kaeSoapClient_Options = array('trace' => 1, 'exceptions' => 0); > > $kaeSoapClient = new SoapClient($kaeSoapClient_WsdlUrl, > > $kaeSoapClient_Options); > > > > $kaeUsername = new SoapVar('MYUSERNAME', XSD_STRING, 'Username', WSSE_URL); > > $kaePassword = new SoapVar('MYPASSWORD', XSD_STRING, 'Password', WSSE_URL); > > $kaeHdr = new SoapVar(array('Username' => $kaeUsername, > > 'Password' => $kaePassword), > SOAP_ENC_OBJECT); > > > > $kaeSoapHeader_NameSpace = WSSE_URL; > > $kaeSoapHeader_Name = "Security"; > > $kaeSoapHeader_Data = $kaeHdr; > > $kaeSoapHeader_MustUnderstand = true; > > $kaeSoapHeader = new SoapHeader($kaeSoapHeader_NameSpace, > > $kaeSoapHeader_Name, > > $kaeSoapHeader_Data, > > > $kaeSoapHeader_MustUnderstand); > > > > There are 2 problems here and I cannot figure out how to fix them: > > - Add the UsernameToken tags > > $WSSE_NS = 'http://schemas.xmlsoap.org/ws/2003/06/secext'; > > class kaeUsernameToken { > public function __construct($Username, $Password) { > $this->Username = $Username; > $this->Password = $Password > } > } > > $kaeUsernameToken = new kaeUsernameToken($kaeUsername, $kaePassword); > $kaeHdr = new SOAPVar($kaeUsernameToken, SOAP_ENC_OBJECT, null, null, > null, $WSSE_NS); > > > - Add the correct namespace to (all) the tags > > $kaeUsername = new SoapVar('MYUSERNAME', XSD_STRING, > 'Username', null, null, $WSSE_NS); > > > Give or take. This is untested, but cribbed from similar code. You may > need to do something similar to embed the UsernameToken object to make > it named correctly. > > -adam > > -- > adam@trachtenberg.com | http://www.trachtenberg.com > author of o'reilly's "upgrading to php 5" and "php cookbook" > avoid the holiday rush, buy your copies today! > > -- > PHP Soap Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- PHP Soap Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php