我正在寻找php soapclient电话的帮助:
呼叫是远程面板,我想拉出日志数据。通过WSDL发布了各种服务,我可以使用几个没有问题。这是清单:
array(12) {
[0]=> string(77) "GetGPTimerChannelsResponse GetGPTimerChannels(GetGPTimerChannels $parameters)"
[1]=> string(74) "GetGPTimerChannelResponse GetGPTimerChannel(GetGPTimerChannel $parameters)"
[2]=> string(74) "SetGPTimerChannelResponse SetGPTimerChannel(SetGPTimerChannel $parameters)"
[3]=> string(47) "GetSlaveResponse GetSlave(GetSlave $parameters)"
[4]=> string(71) "GetLogDataInlineResponse GetLogDataInline(GetLogDataInline $parameters)"
[5]=> string(71) "GetLogItemInlineResponse GetLogItemInline(GetLogItemInline $parameters)"
[6]=> string(59) "GetAlarmListResponse GetAlarmList(GetAlarmList $parameters)"
[7]=> string(50) "GetSyslogResponse GetSyslog(GetSyslog $parameters)"
[8]=> string(47) "SetSlaveResponse SetSlave(SetSlave $parameters)"
[9]=> string(53) "GetVersionResponse GetVersion(GetVersion $parameters)"
[10]=> string(53) "GetTDBInfoResponse GetTDBInfo(GetTDBInfo $parameters)"
[11]=> string(53) "GetLogItemResponse GetLogItem(GetLogItem $parameters)" }
我正在尝试使用需要四个参数的GetLogDataInline服务 - 这些我作为一个数组传递,并且在进行连接时一切正常(请求/响应需要大约30秒才能处理)。
当我查看结果的var_dump / print_r时,它返回NULL,而当我调用__getLastResponse时,我需要填充本地数据库的所有数据。
以下是soapclient调用的代码:
$client = new soapclient ("http://192.168.1.126/cgi-bin/cgi.cgi?WSDL",
array("trace" => 1,
"exceptions" => true,
"cache_wsdl" => WSDL_CACHE_NONE,
"features" => SOAP_SINGLE_ELEMENT_ARRAYS
));
$params = array (
"ResponseType" => "Xml",
"Step" => 15,
"Start" => "2012-06-14T12:00:00+01:00",
"End" => "2012-06-14T23:59:45+01:00"
);
$result = $client -> GetLogDataInline ($params);
var_dump / __getLastResponse的摘录是:
var_dump($client)
object(SoapClient)#1 (4) { ["trace"]=> int(1) ["_features"]=> int(1) ["_soap_version"]=> int(1) ["sdl"]=> resource(4) of type (Unknown) }
var_dump($result)
NULL
__getLastResponse
<?xml version="1.0" encoding="UTF-8" ?>
<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> <GetLogDataResponse xmlns="http://url/RDMPlantTDB/2009/03/13/">
<GetLogDataResult>
<Step>15</Step>
<Start>2012-06-14T12:00:00+01:00</Start>
<End>2012-06-14T23:59:45+01:00</End>
<LogData>
<![CDATA[<?xml version="1.0" encoding="UTF-8" ?>
<Data>
<Fields> <Field>External Temperature</Field> <Field>Workshop Lux Level</Field> <Field>Electricity Pulse 100wh</Field> <Field>Workshop PIR Active</Field> <Field>Boiler Flow Temp</Field> <Field>Outside Lux</Field> <Field>Workshop_Light_Override_Hours</Field> <Field>Water Consumption (Litres)</Field> <Field>Electricity kWh Consumption</Field> <Field>Water Consumption M3</Field> <Field>Gas kWh Consumption</Field> <Field>Outside Lighting</Field> <Field>Heating Effective Setpoint</Field> <Field>Router Reset</Field> <Field>Workshop Lighting State</Field> <Field>Heating Run Hours</Field> <Field>Heating On</Field> <Field>Receptin Percent RH</Field> <Field>Reception Temp</Field> <Field>Reception RH</Field> <Field>Reception Temp</Field> </Fields>
<Entries> <Entry> <Time>2012-06-14T12:00:00+01:00</Time> <Values> <Value>-85.6</Value> <Value>2.1</Value> <Value>-1.0</Value> <Value>Off</Value> <Value>-91.5</Value> <Value>13.8</Value> <Value>0.0</Value> <Value>-1.0</Value> <Value>0.0</Value> <Value>0.0</Value> <Value>-0.1</Value> <Value>Off</Value> <Value>21.0</Value> <Value>Off</Value> <Value>Off</Value> <Value>0.0</Value> <Value>Off</Value> <Value>53.0</Value> <Value>22.0</Value> <Value>53.0</Value> <Value>22.0</Value> </Values> </Entry> <Entry> <Time>2012-06-14T12:00:15+01:00</Time> <Values> <Value>-85.4</Value> <Value>2.1</Value> <Value>-1.0</Value> <Value>Off</Value> <Value>-91.8</Value> <Value>13.8</Value> <Value>0.0</Value> <Value>-1.0</Value> <Value>0.0</Value> <Value>0.0</Value> <Value>-0.1</Value> <Value>Off</Value> <Value>21.0</Value> <Value>Off</Value> <Value>Off</Value> <Value>0.0</Value> <Value>Off</Value> <Value>53.0</Value> <Value>22.0</Value> <Value>53.0</Value> <Value>22.0</Value> </Values> </Entry> <Entry> <Time>2012-06-14T12:00:30+01:00</Time> <Values> <Value>-85.4</Value> <Value>2.1</Value> <Value>-1.0</Value> <Value>Off</Value> <Value>-91.8</Value> <Value>13.8</Value> <Value>0.0</Value> <Value>-1.0</Value> <Value>0.0</Value> <Value>0.0</Value> <Value>-0.1</Value> <Value>Off</Value> <Value>21.0</Value> <Value>Off</Value> <Value>Off</Value> <Value>0.0</Value> <Value>Off</Value> <Value>53.0</Value> <Value>22.0</Value> <Value>53.0</Value> <Value>22.0</Value> </Values> </Entry> <Entry> <Time>2012-06-14T12:00:45+01:00</Time> <Values> <Value>-85.4</Value> <Value>2.1</Value> <Value>-1.0</Value> <Value>Off</Value> <Value>-91.5</Value> <Value>13.7</Value> <Value>0.0</Value> <Value>-1.0</Value> <Value>0.0</Value> <Value>0.0</Value> <Value>-0.1</Value> <Value>Off</Value> <Value>21.0</Value> <Value>Off</Value> <Value>Off</Value> <Value>0.0</Value> <Value>Off</Value> <Value>54.0</Value> <Value>22.0</Value> <Value>54.0</Value> <Value>22.0</Value> </Values> </Entry> <Entry>
答案 0 :(得分:1)
不确定为什么你会得到NULL,但我总是使用下面的方法让SOAP客户端处理错误(如果有的话)。
// Calling soap
try{
// Creating soap server object
$client = new SoapClient("http://192.168.1.126/cgi-bin/cgi.cgi?WSDL");
// Creating parameters
$params = array (
"ResponseType" => "Xml",
"Step" => 15,
"Start" => "2012-06-14T12:00:00+01:00",
"End" => "2012-06-14T23:59:45+01:00"
);
// Calling createUser method
$result = $client->__soapCall('METHOD_NAME',$params);
// Check for a fault
if (is_soap_fault($client)) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
}else{
echo "Result: <BR><pre>";
print_r($result);
echo '</pre>';
}
}catch(SoapFault $fault){
$error = "SOAP Fault: (faultcode: {$fault->faultcode}\n" ."faultstring: {$fault->faultstring})";
echo $error;
}catch(Exception $exception){
$error = $exception;
echo "<BR>".$error;
}
在上面的示例中,您必须使用soap服务器中定义的实际方法替换METHOD_NAME以获取参数并返回结果。但我怀疑第一个参数“ResponseType”,是处理请求的方法所期望的实际第一个参数吗?
您可以尝试运行上面的代码,看看发生了什么错误
我假设在服务器上启用了SOAP扩展。
答案 1 :(得分:0)
PHP soapClient不能很好地支持SOAP中的相对命名空间,这通常是导致此行为的原因。
答案 2 :(得分:0)
如果您的Web服务已启用访问权限,则|新的SoapClient - 第一个问题?使用公共IP公共或DNS | $ result = $ client - &gt;方法($ params)方法; - 第二个问题?使用私有IP,取决于DNS的配置
$client->__setLocation('http:// youDNSorIPpublic /cgi-bin/cgi.cgi');
var_dump($client);
// $ old_location = $ client-&gt; __ setLocation(); //禁用位置 // echo $ old_location;
$result = $client -> Method($params); //new request