我正在尝试使用PHP5进行SOAP调用。这是工作模式:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cat="http://com.xxx.xxxx/management/catalog">
<soapenv:Header/>
<soapenv:Body>
<cat:ManageCustomProducts siteId="0">
<!--You have a CHOICE of the next 2 items at this level-->
<!--0 to 25 repetitions:-->
<cat:task id="?">
<cat:insertCustomProduct manufacturerId="?" manufacturerPartNo="?" categoryId="?" categoryType="default">
<cat:skus>
<!--Zero or more repetitions:-->
<cat:sku type="?" number="?"/>
</cat:skus>
<cat:resources>
<!--Zero or more repetitions:-->
<cat:resource type="?" status="?" url="?"/>
</cat:resources>
<cat:locales>
<!--1 or more repetitions:-->
<cat:locale language="?" country="?">
<cat:descriptions>
<!--Zero or more repetitions:-->
<cat:description type="?">e gero</cat:description>
</cat:descriptions>
<cat:marketingDescription>cum sonoras</cat:marketingDescription>
</cat:locale>
</cat:locales>
</cat:insertCustomProduct>
</cat:task>
</cat:ManageCustomProducts>
这是我生成SOAP XML的代码......
$params=array(array(
'siteId' => '0',
'task' => array('id' => '1',
'insertCustomProduct' => array('manufacturerId' => '10000', 'manufacturerPartNo' => 'abc123', 'categoryId' => '20000', 'categoryType' => 'default',
'skus' => array('sku' => array('type' => 'MANUFACTURPARTNO', 'number' => 'abc123')),
'resources' => array('resource' => array('type' => '500', 'status' => 'Published', 'url' => 'http://content.xxx.com/img.jpg')),
'locales' => array('locale' => array('language' => 'en', 'country' => 'US',
'descriptions' => array('description' => array('_' =>'egeros', 'type' => '1')),
'marketingDescription' => array('_' => 'cum sonoras')
)
)
)
)
)
);
$result = $client->__soapCall("ManageCustomProducts",$params);
结果是......
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://com.xxx.xxx/management/catalog">
<SOAP-ENV:Body>
<ns1:ManageCustomProducts siteId="0">
<ns1:task id="1">
<ns1:insertCustomProduct manufacturerId="10000" manufacturerPartNo="abc123" categoryId="20000" categoryType="default">
<ns1:skus>
<ns1:sku type="MANUFACTURPARTNO" number="abc123"/>
</ns1:skus>
<ns1:resources>
<ns1:resource type="500" status="Published" url="http://content.xxx.com/img.jpg"/>
</ns1:resources>
<ns1:locales>
<ns1:locale language="en" country="US">
<ns1:descriptions>
<ns1:description type="1"/>
</ns1:descriptions>
<ns1:marketingDescription/>
</ns1:locale>
</ns1:locales>
</ns1:insertCustomProduct>
</ns1:task>
</ns1:ManageCustomProducts>
即使我使用的建议格式为:
https://stackoverflow.com/a/1419407/3280665
array(“foo”=&gt; array(“_”=&gt;“cheese”,“bar”=&gt;“moo”));
这应该产生以下XML
<foo bar="moo">cheese</foo>`
没有为description或marketingDescription添加元素值。我做错了什么?
谢谢!
更新:我现在可以添加节点,但如何将Type属性添加到描述节点?
$desc=array();
$desc[]=new SoapVar("This is description 1",XSD_STRING,null,null,'ns1:description');
$desc[]=new SoapVar("This is description 2",XSD_STRING,null,null,'ns1:description');
$description = new SoapVar($desc, SOAP_ENC_OBJECT, null,null,'description');'