XML : Failed to parse SOAP result with PHP

I'm making a SOAP request through the CURL library but I'm struggling to get the desired results. I have met several posts and tried everything, but unfortunately nothing has worked.

Below is the code of my request and my attempt to get the result.

  $requesturl = "http://optimizer.routesavvy.com/OnTerraStopOpt.svc";    $soapenvelope = "(my request)";    $headers = array(                  "Content-type: text/xml;charset=\"utf-8\"",                  "Accept: text/xml",                  "Cache-Control: no-cache",                  "Pragma: no-cache",                  "SOAPAction: http://tempuri.org/IOnTerraStopOpt/GetStopOpt",                   "Content-length: ".strlen($soapenvelope),              );    $ch = curl_init();      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);      curl_setopt($ch, CURLOPT_URL, $requesturl);      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);      curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);      curl_setopt($ch, CURLOPT_TIMEOUT, 10);      curl_setopt($ch, CURLOPT_POST, true);      curl_setopt($ch, CURLOPT_POSTFIELDS, $soapenvelope); // the SOAP request      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);  $response = curl_exec($ch);       curl_close($ch);       $soap     = simplexml_load_string($response);     $response = $soap->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children()->GetStopOptResponse->GetStopOptResult;     var_dump($response);    

Result -> object(SimpleXMLElement)#2 (0) { } (WHY????)

-

SOAP RESPONSE EXAMPLE:

  <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">      <s:Body>          <GetStopOptResponse xmlns="http://tempuri.org/">              <GetStopOptResult xmlns:a="http://schemas.datacontract.org/2004/07/OnTerraStopOpt" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">                  <a:ErrorCode>0</a:ErrorCode>                  <a:OutputLocations>                      <a:Location>                          <a:Latitude>40.631252</a:Latitude>                          <a:LocationName>MyLocation1</a:LocationName>                          <a:Longitude>-74.40383</a:Longitude>                          <a:VisitDurationInMinutes>0</a:VisitDurationInMinutes>                          <a:VisitTime>0001-01-01T00:00:00</a:VisitTime>                      </a:Location>                      <a:Location>                          <a:Latitude>40.604252</a:Latitude>                          <a:LocationName>MyLocation2</a:LocationName>                          <a:Longitude>-74.44612</a:Longitude>                          <a:VisitDurationInMinutes>0</a:VisitDurationInMinutes>                          <a:VisitTime>0001-01-01T00:00:00</a:VisitTime>                      </a:Location>                      <a:Location>                          <a:Latitude>40.553971</a:Latitude>                          <a:LocationName>MyLocation5</a:LocationName>                          <a:Longitude>-74.25938</a:Longitude>                          <a:VisitDurationInMinutes>0</a:VisitDurationInMinutes>                          <a:VisitTime>0001-01-01T00:00:00</a:VisitTime>                      </a:Location>                      <a:Location>                          <a:Latitude>40.808416</a:Latitude>                          <a:LocationName>MyLocation3</a:LocationName>                          <a:Longitude>-74.12111</a:Longitude>                          <a:VisitDurationInMinutes>0</a:VisitDurationInMinutes>                          <a:VisitTime>0001-01-01T00:00:00</a:VisitTime>                      </a:Location>                      <a:Location>                          <a:Latitude>40.847638</a:Latitude>                          <a:LocationName>MyLocation4</a:LocationName>                          <a:Longitude>-74.08754</a:Longitude>                          <a:VisitDurationInMinutes>0</a:VisitDurationInMinutes>                          <a:VisitTime>0001-01-01T00:00:00</a:VisitTime>                      </a:Location>                  </a:OutputLocations>                  <a:OutputMessage>Success</a:OutputMessage>              </GetStopOptResult>          </GetStopOptResponse>      </s:Body>  </s:Envelope>    

-

UTIL: MY FULL PHP CODE -> http://pastebin.com/xe17BE7c

SOAP REQUEST -> http://pastebin.com/mWkAC5eg

SOAP RESPONSE -> http://pastebin.com/U1nDvdmm

Can someone help me?

No comments:

Post a Comment