0

I'm using PHP Soap.

This is a snippet obtained from __getLastRequest(). I'm stuck as to why "Version" comes out as "true" instead of the value that I have set: "1.0"?

In fact, not only do I have a problem with Version, I have a problem with TimeStamp too. The value I set for that was \DateTime::ATOM. Not sure why it's coming out as 2019.

<ns1:OTA_CruiseSailAvailRQ TimeStamp="2019" Version="true" 

The SOAP server refuses to accept my XML, the SoapFault reads as below. I have formed the XML manually in SOAP UI and posted and everything works as expected. However when I do it with PHP Soap, I get this SoapFault and the only two things different are the Version and the TimeStamp.

 [faultstring] => 
Internal Error (from server)

    [faultcode] => 
env:Receiver

here's a bit more of the XML:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://www.opentravel.org/OTA/2003/05/alpha" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="http://services.rccl.com/Interfaces/SailingList">

 <env:Body>

   <ns2:getSailingList>

     <ns1:OTA_CruiseSailAvailRQ TimeStamp="2019" Version="true"


In the WSDL, the definitions of the TimeStamp and the Version as like so:

WSDL

<xs:attribute name="Version" type="xs:decimal" use="required">
            <xs:annotation>
                <xs:documentation xml:lang="en">For all OTA versioned messages, the version of the message is indicated by a decimal value.</xs:documentation>
            </xs:annotation>
</xs:attribute>

<xs:attribute name="TimeStamp" type="xs:dateTime" use="optional">
            <xs:annotation>
                <xs:documentation xml:lang="en">Indicates the creation date and time of the message in UTC using the following format specified by ISO 8601; YYYY-MM-DDThh:mm:ssZ with time values using the 24 hour clock (e.g. 20 November 2003, 1:59:38 pm UTC becomes 2003-11-20T13:59:38Z).</xs:documentation>
            </xs:annotation>
</xs:attribute>

Here is how I set the values and initiate the SOAP call

$test = new MyNamespace\OTA_CruiseSailAvailRQ();
$d = new DateTime('NOW');

$test->setTimeStamp($d);
$test->setVersion(1.0);    


$sailCall = new MyNamespace\Cruise_FIT_External(['trace' => 1,
                                   'exception' => 0,
                                   'login' => 'xxxxxxx', 
                                   'password' => 'xxxxxxxx',
                                  'soap_version' => SOAP_1_2]);


$resp = $sailCall->getSailingList(new MyNamespace\getSailingList($test));

I have used the Wsdl2PhpGenerator to generate my classes from my WSDL. That's why you see Cruise_FIT_External and you don't see a direct instance of SoapClient. But it's extending SoapClient. So we are good there.

namespace MyNamespace;

class Cruise_FIT_External extends \SoapClient
{
    /**
     * @param getSailingList $parameters
     * @return getSailingListResponse
     */
    public function getSailingList(getSailingList $parameters)
    {

      return $this->__soapCall('getSailingList', array($parameters));
    }
}

This is how the setTimestamp and SetVersion functions are defined. Again, this is code output by the Wsdl2PhpGenerator. So I think it's good.


namespace MyNamespace;

class OTA_CruiseSailAvailRQ
{

    /**
     * @var float $Version
     */
    protected $Version = null;

    /**
     * @var \DateTime $TimeStamp
     */
    protected $TimeStamp = null;

    /**
     * @param \DateTime $TimeStamp
     * @return \MyNamespace\OTA_CruiseSailAvailRQ
     */
    public function setTimeStamp(\DateTime $TimeStamp)
    {
      $this->TimeStamp = $TimeStamp->format(\DateTime::ATOM);
      return $this;
    }


    /**
     * @return \DateTime
     */
    public function getTimeStamp()
    {
      if ($this->TimeStamp == null) {
        return null;
      } else {
        try {
            return DateTime::createFromFormat(\DateTime::ATOM, $this->TimeStamp); 
          // this below was the original line. didn't work. changed it to the line above. that didn't work either.
          //return new \DateTime($this->TimeStamp); 
           return $this->TimeStamp;
        } catch (\Exception $e) {
          return false;
        }
      }
    }

    /**
     * @return float
     */
    public function getVersion()
    {
      return $this->Version;
    }

    /**
     * @param float $Version
     * @return \MyNamespace\OTA_CruiseSailAvailRQ
     */
    public function setVersion($Version)
    {
      $this->Version = $Version;
      return $this;
    }

The expected output, if this is solved, should be as shown below. I know this works because when I use SOAP UI and manually create the XML and post, everything works as expected.

<ns1:OTA_CruiseSailAvailRQ TimeStamp="2019-05-11T15:30:41-05:00" Version="1.0" 

Thanks in advance for any help!

Mark CR
  • 1
  • 1

1 Answers1

0

Overjoyed to find another method to call these SOAP API's rather than using Classes and SoapClient

Used this technique from this Stackoverflow post - uses Curl instead. Such a life-saver!

All works well!

Mark CR
  • 1
  • 1