SoapClient 未从 SimpleXMLObject 正确呈现 xml

SoapClient not rendering correct xml from SimpleXMLObject

我们有一个应用程序可以在 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 证书。但是只发送了 1 个证书对象。只有第一个。

我从简单的XML 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>

我们发现这是 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,
                        ]
                    ]
                ]
            ]
        ]