Reputation: 751
I am working with an API and I am new to PHP SOAP.. I am trying to create a request to get a vehicle value and am looking to get the response value.
The following is a sample SOAP 1.1 request. The placeholders shown need to be replaced with actual values.
POST /vehicles/vehicle.asmx HTTP/1.1
Host: webservice.nada.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://webservice.nada.com/getDefaultVehicleAndValueByVin"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getDefaultVehicleAndValueByVin xmlns="http://webservice.nada.com/">
<vehicleRequest>
<Vin>string</Vin>
<Region>int</Region>
<Mileage>int</Mileage>
</vehicleRequest>
</getDefaultVehicleAndValueByVin>
Here is the SOAP Client URL Call -
$clientV = new soapclient('http://webservice.nada.com/vehicles/vehicle.asmx?wsdl',array(
// Stuff for development. 'trace' => 1,'exceptions' => 1, 'cache_wsdl' => 0));
This is what ive tried but get no result -
$clientV = new soapclient('http://webservice.nada.com/vehicles/vehicle.asmx?wsdl',array(// Stuff for development. 'trace' => 1,'exceptions' => 1, 'cache_wsdl' => 0));
$params = new \SoapVar("<vehicleRequest><Vin>5YFBURHE3FP331896</Vin><Region>10</Region><Mileage>100000</Mileage></vehicleRequest>", XSD_ANYXML);
$result = $client->Echo($params);
Another method I tried but get error parsing WSDL
$wsdl = '
POST /vehicles/vehicle.asmx HTTP/1.1
Host: webservice.nada.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://webservice.nada.com/getDefaultVehicleAndValueByVin"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getDefaultVehicleAndValueByVin xmlns="http://webservice.nada.com/">
<vehicleRequest>
<Vin>5YFBURHE3FP331896</Vin>
<Region>1</Region>
<Mileage>100</Mileage>
</vehicleRequest>
</getDefaultVehicleAndValueByVin>
</soap:Body>
</soap:Envelope>
';
try {
$clientC = @new SOAPClient($wsdl); for $wsdl
$response = $clientC->getDefaultVehicleAndValueByVin(array('key' => 'val'));
} catch (Exception $e) {
echo $e->getMessage();
}
die(var_dump($response));
Here is the error I get -
SOAP-ERROR: Parsing WSDL: Couldn't load from ' POST /vehicles/vehicle.asmx HTTP/1.1 Host: webservice.nada.com Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://webservice.nada.com/vehicles/vehicle.asmx?wsdl" 5YFBURHE3FP331896 1 100 ' : failed to load external entity " POST /vehicles/vehicle.asmx HTTP/1.1 Host: webservice.nada.com Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://webservice.nada.com/vehicles/vehicle.asmx?wsdl"
Upvotes: 4
Views: 12082
Reputation: 19635
Something like this should help you get started. I am not 100% familiar with the NADA API so I don't know what valid values are for some of the parameters... you'll have to fill in the correct values (e.g. for Token, Period, VehicleType, and Region).
$clientV = new SoapClient('http://webservice.nada.com/vehicles/vehicle.asmx?wsdl',array('trace' => 1,'exceptions' => 1, 'cache_wsdl' => 0));
$params = new stdClass();
$params->Token = '';
$params->Period = 1;
$params->VehicleType = '';
$params->Vin = '5YFBURHE3FP331896';
$params->Region = 1;
$params->Mileage = 100;
$result = $clientV->getDefaultVehicleAndValueByVin(array('vehicleRequest' => $params));
Upvotes: 3