将Soap格式化为PHP查询

时间:2016-09-02 20:49:45

标签: php soap

我有一个名为selectCmDevice的soap函数,我无法格式化成php语句来运行查询。在WSDL中,selectCmDevice看起来像这样(我只包括相关部分);

<element name="selectCmDevice">
<complexType>
<sequence>
<element name="StateInfo" type="xsd:string"/>
<element name="CmSelectionCriteria" type="tns:CmSelectionCriteria"/>
</sequence>

<complexType name="CmSelectionCriteria">
<sequence>
<element name="MaxReturnedDevices" nillable="true" type="xsd:unsignedInt"/>
<element name="DeviceClass" nillable="true" type="xsd:string"/>
<element name="Model" nillable="true" type="xsd:unsignedInt"/>
<element name="Status" nillable="true" type="xsd:string"/>
<element name="NodeName" nillable="true" type="xsd:string"/>
<element name="SelectBy" nillable="true" type="tns:CmSelectBy"/>
<element name="SelectItems" nillable="true" type="tns:ArrayOfSelectItem"/>
<element name="Protocol" nillable="true" type="tns:ProtocolType"/>
<element name="DownloadStatus" nillable="true" type="tns:DeviceDownloadStatus"/>
</sequence>

<simpleType name="CmSelectBy">
<restriction base="xsd:string">
<enumeration value="Name"/>
<enumeration value="IPV4Address"/>
<enumeration value="IPV6Address"/>
<enumeration value="DirNumber"/>
<enumeration value="Description"/>
</restriction>

<complexType name="ArrayOfSelectItem">
<sequence>
<element maxOccurs="unbounded" minOccurs="0" name="item" type="tns:SelectItem"/>
</sequence>

<complexType name="SelectItem">
<sequence>
<element name="Item" nillable="true" type="xsd:string"/>
</sequence>

<simpleType name="ProtocolType">
<restriction base="xsd:string">
<enumeration value="Any"/>
<enumeration value="SCCP"/>
<enumeration value="SIP"/>
<enumeration value="Unknown"/>
</restriction>

<simpleType name="DeviceDownloadStatus">
<restriction base="xsd:string">
<enumeration value="Any"/>
<enumeration value="Upgrading"/>
<enumeration value="Successful"/>
<enumeration value="Failed"/>
<enumeration value="Unknown"/>
</restriction>
</simpleType>

所以,当我在PHP中运行它时,我已经编写了一个查询,但它并没有提取我指定的内容 - 它会拉动系统中的所有内容。它不接受 insertVariableHere ;

中的任何内容
$deviceIP = $soapClient->selectCmDevice
(array('StateInfo' => '', 'CmSelectionCriteria' => 
(array('SelectBy'=>'Name','Status'=>'Registered','SelectItems'=>
array('SelectItem[0]'=>
array('Item'=>'insertVariableHere'))))));

我不确定是否在php中正确写入了tns的soap值。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

为了了解基于WSDL的实际XML查询的外观,请在程序SoapUI中运行查询。它旨在概述实际发送和接收的内容 一旦你知道了xml的外观,最初将整个XML字符串作为SOAPVAR发送到PHP中的selectCmDevice:

$xml='*copy of xml-request from SoapUI*';
$client=new SoapClient($wsdl,array('trace' => 1, 'exception' => 0));
$param=new SoapVar($xml,XSD_ANYXML);
$result=$client->selectCmDevice($param);

现在你应该有一个有效的php示例查询。从这里您可以根据需要修改您的电话