PHP SOAP Header construction

php, soap, wsdl

Solution

Just try to use an anonymous class instead of an array :

// Use standard class and set magic properties.
$header = new stdClass();
$header->siteId = '0';
$header->Username = 'MEMBERSHIP';
$header->Password = 'P@ssw0rd';

Problem

So basically I want the SOAP header to be like this: ``` <soapenv:Header> <v1:loginDetails> <v11:Id>0</v11:Id> <v11:username>MEMBERS</v11:username> $ <v11:password>0x909711E5,0xE301F82A,0x0E2783CC,0xAF6BC3DB,0x57727CFB</v11:password> </v1:loginDetails> </soapenv:Header> <soapenv:Body> <v11:GetNextAvailableMemberNumberRequest> <v11:Id>1</v11:Id> <v11:memberId>1</v11:memberId> </v11:GetNextAvailableNumberRequest> </soapenv:Body> </soapenv:Envelope> ``` But instead, now I have this: ``` <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www..com/membership/types/v1_0"> <SOAP-ENV:Header> <ns1:loginDetails> <item><key>siteId</key><value>0</value></item> <item><key>Username</key><value>MEMBERSHIP</value></item> <item><key>Password</key><value>P@ssw0rd</value></item> </ns1:loginDetails> </SOAP-ENV:Header> <SOAP-ENV:Body> <ns1:GetNextAvailableMemberNumberRequest/> <param1>1</param1> </SOAP-ENV:Body> </SOAP-ENV:Envelope> ``` And this is the php code that I'm currently using: ``` $client = new SOAPClient('http://192.168.180.128:8010//membershipService?wsdl',array('trace' => true)); $client->__setSoapHeaders(null); $headerbody = array ('siteId' => '0','Username' => 'MEMBERSHIP', 'Password' => 'P@ssw0rd'); $header = new SOAPHeader('http://www.com/club/services/membership/types/v1_0','loginDetails',$headerbody); $client->__setSoapHeaders($header); ``` Where have I gone wrong? I seems unable to construct the header properly.

Original source