我们有一个应用程序,可以在SimpleXML中构建正确的XML请求。用$element->asXml()
输出时,我也得到了正确的XML。但是,当将SimpleXML对象传递给soapclient时,它将剥离数组中的所有键。
我尝试了几种方法来解决此问题。将键分配给元素。 Soapclient的一些功能,并将所有内容转换为数组。没有结果。
这是我要实现的目标的抽象版本。
$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);
在这种情况下,我的WSDL具有maxOccurence=Unbound
可以进行认证。但是仅发送一个证书对象。只有第一个。
simpleXML asXml()函数的作用是什么
<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>
这是正确的
肥皂客户如何发送
<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>
这里提供更多上下文是此请求的WSDL部分
<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>
答案 0 :(得分:3)
我们发现这是PHP SoapClient与SimpleXML结合的错误。通过将数组传递给SoapClient进行完全相同的操作时,XML的格式正确。我们将得出这种方法。目前无法调试SoapClient。
[
'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,
]
]
]
]
]