SoapClient无法从SimpleXMLObject渲染正确的xml
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SoapClient无法从SimpleXMLObject渲染正确的xml相关的知识,希望对你有一定的参考价值。
我们有一个在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有qazxsw poi证书。但只发送1个certifcate对象。只有第一个。
我从simpleXML asXml()函数获得的是什么
maxOccurence=Unbound
这是对的
肥皂客户如何发送
<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>
为了给出更多上下文,这个请求的WSDL部分
<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>
答案
我们发现这是php SoapClient与SimpleXML结合使用时的一个错误。通过将数组传递给SoapClient完成相同的操作时,XML格式正确。我们将得到这种方法。目前无法调试SoapClient。
<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>
以上是关于SoapClient无法从SimpleXMLObject渲染正确的xml的主要内容,如果未能解决你的问题,请参考以下文章
PHP - SoapClient::SoapClient 无法打开流:连接被拒绝
使用php soapclient工具包显示访问netsuite wsdl无法加载wsdl