PHP的SOAP请求中存在错误

时间:2016-06-16 08:33:33

标签: php soap wsdl soap-client

此请求:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <soap:Body>
  <Buy xmlns="http://tempuri.org/">
  <perf>
   <param1>1111</param1>
   <param2>2222</param2>
  </perf>
 </Buy>
</soap:Body></soap:Envelope>

我使用SoapClient创建请求:

$client = new SoapClient("http://0.0.0.0:8080/Service1.asmx?wsdl",
 array(
  'trace' => true,
  'exceptions'=>true
 ));

功能“getTypes”和“getFunctions”工作正确

$types = $client->__getTypes();
$functions = $client->__getFunctions ();

我正在创建对象,我正在等待结果:

$std = new stdClass();
$std->param1 = '1111';
$std->param2 = '2222';

ini_set("soap.wsdl_cache_enabled", "0"); // disallow cache WSDL 

$result = $client->Buy( array('perf' => $std ) );
var_dump($result); exit;

我收到了一个错误:SoapFault:

Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /var/www/index.php:86 Stack trace: #0 [internal function]: SoapClient->__doRequest('__call('Buy', Array) #2 /var/www/index.php(86): SoapClient->Buy(Array) #3 {main} thrown in /var/www/index.php on line 86

在apache的日志中

PHP Fatal error:  Uncaught SoapFault exception: [HTTP] Could not connect to host in /var/www/index.php:86\nStack trace:\n#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://0.0.0...', 'http://tempuri....', 1, 0)\n#1 /var/www/index.php(86): SoapClient->__call('Buy', Array)\n#2 /var/www/index.php(86): SoapClient->Buy(Array)\n#3 {main}\n  thrown in /var/www/index.php on line 86

请帮帮我 ,可能是,我创建了参数不正确的对象?

1 个答案:

答案 0 :(得分:1)

尽量不要混合数组和对象。检查一下:

$result = $client->Buy( array('perf' => array('param1' => '1111', 'param2' => '2222')) );

或者这个:

$result = $client->Buy( (object) array('perf' => (object) array('param1' => '1111', 'param2' => '2222')) );
相关问题