我正在尝试在PHP(5.2.5)中进行非WSDL调用。我确定我错过了一些简单的事情。此调用有一个参数,一个名为“timezone”的字符串:
$URL = 'http://www.nanonull.com/TimeService/TimeService.asmx';
$client = new SoapClient(null, array(
'location' => $URL,
'uri' => "http://www.Nanonull.com/TimeService/",
'trace' => 1,
));
// First attempt:
// FAILS: SoapFault: Object reference not set to an instance of an object
$return = $client->__soapCall("getTimeZoneTime",
array(new SoapParam('ZULU', 'timezone')),
array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
);
// Second attempt:
// FAILS: Generated soap Request uses "param0" instead of "timezone"
$return = $client->__soapCall("getTimeZoneTime",
array('timezone'=>'ZULU' ),
array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
);
感谢您的任何建议 -Dave
答案 0 :(得分:11)
@Dave C的解决方案对我不起作用。环顾四周,我提出了另一个解决方案:
$URL = 'http://www.nanonull.com/TimeService/TimeService.asmx';
$client = new SoapClient(null, array(
'location' => $URL,
'uri' => "http://www.Nanonull.com/TimeService/",
'trace' => 1,
));
$return = $client->__soapCall("getTimeZoneTime",
array(new SoapParam(new SoapVar('ZULU', XSD_DATETIME), 'timezone')),
array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
);
希望这可以帮助某人。
答案 1 :(得分:10)
感谢。这是现在有效的完整示例:
$URL = 'http://www.nanonull.com/TimeService/TimeService.asmx';
$client = new SoapClient(null, array(
'location' => $URL,
'uri' => "http://www.Nanonull.com/TimeService/",
'trace' => 1,
));
$return = $client->__soapCall("getTimeZoneTime",
array(new SoapParam('ZULU', 'ns1:timezone')),
array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
);
答案 2 :(得分:5)
问题在于参数中缺少命名空间信息。我使用了你的例子中的第一个例子,因为它最接近我的想法。
如果您更改了该行:
array(new SoapParam('ZULU', 'timezone')),
为:
array(new SoapParam('ZULU', 'ns1:timezone')),
它应该给你你期望的结果。
答案 3 :(得分:0)
您可以尝试在您的参数周围添加另一个array()
调用,如下所示:
$params = array('timezone'=>'ZULU' );
$return = $client->__soapCall("getTimeZoneTime",
array($params),
array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
);
我无法测试,但你可以。