我有一个XML示例:
<?xml version="1.0" encoding="windows-1250"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ImportPackagesExt xmlns="PPLIEGate">
<FirCode>ppltest</FirCode>
<Packages>
<Items>
<anyType xsi:type="Package">
<PackageID>40080145103</PackageID>
<ZipCode>16300</ZipCode>
<Country>CZ</Country>
<ErrorCode>0</ErrorCode>
<ErrorMessage></ErrorMessage>
</anyType>
<anyType xsi:type="Package">
<PackageID>40010529207</PackageID>
<ZipCode>15500</ZipCode>
<Country>CZ</Country>
<ErrorCode>0</ErrorCode>
<ErrorMessage></ErrorMessage>
</anyType>
</Items>
</Packages>
</ImportPackagesExt>
</soap:Body>
</soap:Envelope>
但是我的PHP脚本会返回错误。
$packs = [
[
'PackageID' => '40080145103',
'ZipCode' => '16300',
'Country' => 'CZ',
'ErrorCode' => 0,
'ErrorMessage' => '',
],
[
'PackageID' => '40010529207',
'ZipCode' => '15500',
'Country' => 'CZ',
'ErrorCode' => 0,
'ErrorMessage' => '',
],
];
$items = [];
foreach ($packs as $pack) {
$items[] = new SoapVar($pack, SOAP_ENC_ARRAY, XSD_ANYTYPE, null, 'Package');
}
$packages = [
'FirCode' => $firCode,
'Packages' => [
'Items' => $items,
'ErrorCode' => 0,
],
'DepID' => '00',
];
$response = $soap->ImportPackagesExt($packages);
错误说:服务器无法处理请求。 ---&GT;无法将“System.Xml.XmlNode []”类型的对象转换为“Package”类型。
我仍然无法弄清楚如何为“包”定义结构。
答案 0 :(得分:0)
知道了。变量$ items也必须作为SoapVar的实例传递。
$parameters = [
'FirCode' => $firCode,
'Packages' => [
'Items' => new SoapVar($items, SOAP_ENC_OBJECT),
'ErrorCode' => 0,
'ErrorMessage' => '',
],
'DepID' => '00',
];