How to Pass an Array into a PHP Soapclient Call

How to pass an array into a PHP SoapClient call

'stay' has to be defined just once. This should be the right answer:

$xml = array('reservation' => array(
'stays' => array(
'stay' => array(
array(
'start_date' => '2011-01-01',
'end_date' => 2011-01-15
),
array(
'start_date' => '2011-01-01',
'end_date' => 2011-01-15
)
)
)
));

Passing array to SOAP function in PHP

You can use this -v function to convert a array to a object tree:

function array_to_objecttree($array) {
if (is_numeric(key($array))) { // Because Filters->Filter should be an array
foreach ($array as $key => $value) {
$array[$key] = array_to_objecttree($value);
}
return $array;
}
$Object = new stdClass;
foreach ($array as $key => $value) {
if (is_array($value)) {
$Object->$key = array_to_objecttree($value);
} else {
$Object->$key = $value;
}
}
return $Object;
}

Like so:

$data = array(
'GetResultListRequest' => array(
'Filters' => array(
'Filter' => array(
array('Name' => 'string', 'Value' => 'string'), // Has a numeric key
array('Name' => 'string', 'Value' => 'string'),
)
)
)
);
$Request = array_to_objecttree($data);

Passing a PHP array in a SOAP call

It's hard to test this without a SOAP server with your WSDL to go against. You should be able to create associative arrays like so:

$responses = array();
$responses[] = array("QuestionAnswerID" => someint, "QuestionID" => someint);
$responses[] = array("QuestionAnswerID" => someint, "QuestionID" => someint);

$response = array("Response" => $responses);

$soapData = array("Responses" => $response);

How Do I Add an Attribute to an Array for a SoapClient Request In PHP

After some digging around in the manual I managed to find a solution which works :)

'Goods' => array('_' => '', 'Type'=>'EGoods',
'Description' => '$Description', 'Quantity' => '$qty');

Produces

<Goods Type="EGoods">              
<Description>Test</Description>
<Quantity>1</Quantity>
</Goods>

Solution Found Here PHP: SoapParam::SoapParam - Manual Comment 114146

I had to slightly modify it to work, if you compare my array structure to that in the original you see what changes I had to make.

Paul

Soapclient passing the data for the body of request into __soapCall

Probably best not to use $soap->__soapCall(), as that's really a "low level API", and only useful when you are in a "non-WSDL mode":

https://php.net/manual/en/soapclient.soapcall.php

Why not try calling the CheckAddress() method on the $soap object, e.g.

$response = $soap->CheckAddress($value1, $value2, $value3);
$response = $soap->CheckAddress($data);

And if you're first argument uses a keyed array, you should be able to do:

$response = $soap->CheckAddress(['name' => 'value']);

Problem in PHP and SOAP-Client Call method two parameters and one ArrayMultidimensional

My Solution is use SoapVar() in $parametersArray and is valid for string XML BaseEncode64 :

$ws = new \SoapClient($this->getWSUrl()
, [
//'trace' => true,
'encoding' => 'utf-8',
'connection_timeout' => '10',
'cache_wsdl' => WSDL_CACHE_MEMORY,
]);

$parm = array();
$subparm = array();

$parm[] = new SoapVar($parametersArray['token'], XSD_STRING, null, null, 'token');
$parm[] = new SoapVar($parametersArray['usuario'], XSD_STRING, null, null, 'usuario');
$subparm[] = new SoapVar($parametersArray['archivo']['fileType'], XSD_STRING, null, null, 'fileType');
$subparm[] = new SoapVar($parametersArray['archivo']['nombre'], XSD_STRING, null, null, 'nombre');
$subparm[] = new SoapVar($parametersArray['archivo']['xml'], XSD_STRING, null, null, 'xml');
$parm[] = new SoapVar($subparm, SOAP_ENC_OBJECT, null, null, 'archivo');
$resp = new SoapVar($parm, SOAP_ENC_OBJECT);

$data = json_decode(json_encode($ws->generarSolicitud($resp)->return), true);

//exit(debug($ws->__getLastRequest()));

Alternative easy, is not valid for my dataArray in 'xml', change stringBaseCode64 ;-(

$ws = new \SoapClient($this->getWSUrl()
, [
//'trace' => true,
'encoding' => 'utf-8',
'connection_timeout' => '10',
'cache_wsdl' => WSDL_CACHE_MEMORY,
]);

$data = json_decode(json_encode($ws->generarSolicitud($parametersArray)->return), true);

//exit(debug($ws->__getLastRequest()));


Related Topics



Leave a reply



Submit