Mс1er
Mс1er

Reputation: 59

There is an error in SOAP-request by PHP

This request:

<?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>

I create request with SoapClient:

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

Function "getTypes" and "getFunctions" work correct

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

I'm creating object and I'm waiting result:

$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;

I got an error: 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

In the logs of 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

Please, help me), may be, I created object with parameters not correct?

Upvotes: 2

Views: 1515

Answers (1)

Grzegorz Adam Kowalski
Grzegorz Adam Kowalski

Reputation: 5565

Try not to mix arrays and objects. Check this:

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

Or this:

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

Upvotes: 1

Related Questions