4

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"

5
  • What are the specific problems you are facing? What have you tried so far? I'm afraid SO is neither a "What is the best tutorial" nor a "please write me some code" service - as you for sure know already. Given your previous questions you have enough php skills to give it a try! Commented Mar 26, 2019 at 0:30
  • Yes Im not looking for someone to write the code for me..Im looking for how to structure the XML Call in a php script. Using that SOAP URL call im not sure how to include the XML call. Again ive never used SOAP so just looking for some direction or starting point Commented Mar 26, 2019 at 0:35
  • I updated the question with my attempt but it doesn't return any result. Do I need to add all the XML into the $params? Commented Mar 26, 2019 at 0:52
  • What you are assigning to the variable $wsdl is not a WSDL document, it is an HTTP request. You need to load a proper WSDL doc. Commented Mar 26, 2019 at 2:19
  • @BrianDriscoll thanks, I found this as an example where they had the $wsdl as the xml data. I am struggling to find a way to request that xml data in the php script Commented Mar 26, 2019 at 2:57

1 Answer 1

3

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));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.