php 的 soap 返回数组:
services.php文件:
<?php
class services {
/**
* Getdnstatus one string from each other
*
* @param string $dn The first string of the subtraction
* @return array The status of the tel
*/
public function getdnstatus($dn){
if($dn == "8101"){
$status_arr = array("1","通话","1");
}else{
$status_arr = array("0","空闲","0");
}
return serialize($status_arr);
}
}
$server = new SoapServer('service.wsdl', array('soap_version' => SOAP_1_2));
$server->setClass("services");
$server->handle();
?>
service.wsdl文件:
<?xml version='1.0' encoding='UTF-8'?>
<!-- WSDL file generated by Zend Studio. -->
<definitions name="service" targetNamespace="urn:service" xmlns:typens="urn:service" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="getdnstatus">
<part name="dn" type="xsd:string"/>
</message>
<message name="getdnstatusResponse">
<part name="getdnstatusReturn" type="xsd:anyType"/>
</message>
<portType name="servicesPortType">
<operation name="getdnstatus">
<documentation>
Getdnstatus one string from each other
</documentation>
<input message="typens:getdnstatus"/>
<output message="typens:getdnstatusResponse"/>
</operation>
</portType>
<binding name="servicesBinding" type="typens:servicesPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getdnstatus">
<soap:operation soapAction="urn:servicesAction"/>
<input>
<soap:body namespace="urn:service" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body namespace="urn:service" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="serviceService">
<port name="servicesPort" binding="typens:servicesBinding">
<soap:address location="http://10.1.7.153/soap/services.php"/>
</port>
</service>
</definitions>
客户端文件:client.php
<?php
//$client = new SoapClient('http://10.1.7.153/soap/service.wsdl');
$client = new SoapClient("http://10.1.7.153/soap/services.php?WSDL");
try {
$result = array();
$result = $client->getdnstatus('8101');
var_dump(unserialize($result));
} catch(SoapFault $e) {
print "Sorry an error was caught executing your request: {$e->getMessage()}";
}
?>