Reputation: 211
We have an application that builds a correct XML request in SimpleXML. When outputting this with $element->asXml()
I also get the correct XML. However when passing the SimpleXML object to the soapclient it will stripp all keys in array's.
I have tried several ways to fix this. Assigning keys to the elements. Several Soapclient features, and turning everything into an array. No result.
This is a abstract version of what i'm trying to achieve.
$populate = new SimpleXMLElement('<Populate/>');
$data = $populate->addChild('data');
$roleKeysElement = $data->addChild('RoleKeys');
$roleKeysElement->addChild('Operation', $settings[PopulateSettings::ROLE_KEYS] ?? Operations::MIRROR);
$roleKeyElement1 = $roleKeysElement->addChild('RoleKey');
$keyElement1 = $roleKeyElement1->addChild('Key');
$certificateElement = 1->addChild('Certificate');
$certificateElement->addChild('ValidUntil', 1);
$certificateElement->addChild('Password', 2);
$certificateElement->addChild('Thumbprint', 3);
$certificateElement->addChild('Serial', 4);
$certificateElement->addChild('Base64Data', 5);
$roleKeyElement2 = $roleKeysElement->addChild('RoleKey');
$keyElement2 = $roleKeyElement2->addChild('Key');
$certificateElement = $keyElement2->addChild('Certificate');
$certificateElement->addChild('ValidUntil', 1);
$certificateElement->addChild('Password', 2);
$certificateElement->addChild('Thumbprint', 3);
$certificateElement->addChild('Serial', 4);
$certificateElement->addChild('Base64Data', 5);
$response = $this->client->populate($populate);
My WSDL has maxOccurence=Unbound
for certifcate in this case. But only 1 certifcate object is send. Only the first one.
What im getting from the simpleXML asXml() function is
<Populate>
<data>
<RoleKeys>
<Operation>
Mirror
</Operation>
<RoleKey>
<Key>
<Certificate>
<ValidUntil>
1
</ValidUntil>
<Password>
2
</Password>
<Thumbprint>
3
</Thumbprint>
<Serial>
4
</Serial>
<Base64Data>
5
</Base64Data>
</Certificate>
</Key>
</RoleKey>
<RoleKey>
<Key>
<Certificate>
<ValidUntil>
1
</ValidUntil>
<Password>
2
</Password>
<Thumbprint>
3
</Thumbprint>
<Serial>
4
</Serial>
<Base64Data>
5
</Base64Data>
</Certificate>
</Key>
</RoleKey>
</RoleKeys>
</data>
</Populate>
This is correct
How ever the soap clients sends
<Populate>
<data>
<RoleKeys>
<Operation>
Mirror
</Operation>
<RoleKey>
<Key>
<Certificate>
<ValidUntil>
1
</ValidUntil>
<Password>
2
</Password>
<Thumbprint>
3
</Thumbprint>
<Serial>
4
</Serial>
<Base64Data>
5
</Base64Data>
</Certificate>
</Key>
</RoleKey>
</RoleKeys>
</data>
</Populate>
To give a little more context here is the WSDL part of this request
<complexType name="KeyType">
<sequence>
<element minOccurs="0" maxOccurs="1" name="KeyUnlocks" type="s:string" />
<choice minOccurs="1" maxOccurs="1">
<element minOccurs="0" maxOccurs="1" name="Credentials">
<complexType>
<sequence>
<element minOccurs="0" maxOccurs="1" name="Username" type="s:string" />
<element minOccurs="0" maxOccurs="1" name="Password" type="s:string" />
</sequence>
</complexType>
</element>
<element minOccurs="0" maxOccurs="1" name="Certificate">
<complexType>
<sequence>
<element minOccurs="1" maxOccurs="1" name="ValidUntil" type="s:dateTime" />
<element minOccurs="0" maxOccurs="1" name="Password" type="s:string" />
<element minOccurs="0" maxOccurs="1" name="Thumbprint" type="s:string" />
<element minOccurs="0" maxOccurs="1" name="Serial" type="s:string" />
<element minOccurs="0" maxOccurs="1" name="Base64Data" type="s:base64Binary" />
</sequence>
</complexType>
</element>
</choice>
</sequence>
</complexType>
Upvotes: 2
Views: 189
Reputation: 211
We found that this is a bug in with the php SoapClient in combination with SimpleXML. When doing the exact same thing with passing an array to the SoapClient the XML is formatted correctly. We will result to this method. No way to debug the SoapClient at this time.
[
'data' => [
'RoleKeys' => [
'Operation' => 'Mirror',
'RoleKey' => [
[
'ValidUntil' => 1,
'Password' => 2,
'Thumbprint' => 3,
'Serial' => 4,
'Base64Data' => 5,
],
[
'ValidUntil' => 1,
'Password' => 2,
'Thumbprint' => 3,
'Serial' => 4,
'Base64Data' => 5,
]
]
]
]
]
Upvotes: 4