i'm trying to consume a SOAP API DOC WSDL and for some reason the requests always fail unless i use stdClass instances as arguments, and i'm trying to find a way around this cause i just don't like doing it this way and would much prefer to use associative arrays instead.
/* I'd like to get rid of these two classes if possible */
class countriesRequest{
public $companyCode = "9999";
public $allCountries = true;
}
class getCountries{
public $objRequest;
function __construct()
{
$this->objRequest = new countriesRequest;
}
}
class Countries extends ApiMethod
{
/**
* @var string API Endpoint
*/
private $endpoint;
public function getAllCountries() {
$client = new SoapClient("http://jsserver20.jimpisoft.pt/Rentway_WS_Demo/getCountries.asmx?wsdl", ['trace' => 1]);
try {
$result = $client->getCountries(new getCountries());
var_dump($result->getCountriesResult->countries->any);
} catch(SoapFault $exception) {
dd($client->__getLastRequest());
}
}
}
Whenever i try to use associative arrays, the SOAP Server returns an error "Object reference not set to an instance of an object." so for those of you more experienced with SOAP, does this service in this case require me to use stdClasses as arguments? Or is there any way i can use assoc arrays?
You could create the associative array and later transform it to a stdClass
with:
$object = json_decode(json_encode($yourAssociativeArray));
or if isn't a nested array (just key value) you can do:
$object = (object)$yourAssociativeArray;